46 void RandomNumberGenerator::SetEntropySource(
EntropySource source) {
47 LockGuard<Mutex> lock_guard(entropy_mutex.
Pointer());
48 entropy_source = source;
52 RandomNumberGenerator::RandomNumberGenerator() {
54 if (FLAG_random_seed != 0) {
55 SetSeed(FLAG_random_seed);
60 { LockGuard<Mutex> lock_guard(entropy_mutex.
Pointer());
61 if (entropy_source !=
NULL) {
63 if (entropy_source(reinterpret_cast<unsigned char*>(&seed),
71 #if V8_OS_CYGWIN || V8_OS_WIN
74 unsigned first_half, second_half;
75 errno_t result = rand_s(&first_half);
77 result = rand_s(&second_half);
79 SetSeed((static_cast<int64_t>(first_half) << 32) + second_half);
82 FILE*
fp = fopen(
"/dev/urandom",
"rb");
85 size_t n = fread(&seed,
sizeof(seed), 1, fp);
101 int64_t seed = Time::NowFromSystemTime().ToInternalValue() << 24;
102 seed ^= TimeTicks::HighResolutionNow().ToInternalValue() << 16;
103 seed ^= TimeTicks::Now().ToInternalValue() << 8;
105 #endif // V8_OS_CYGWIN || V8_OS_WIN
109 int RandomNumberGenerator::NextInt(
int max) {
114 return static_cast<int>((max *
static_cast<int64_t
>(Next(31))) >> 31);
120 if (rnd - val + (max - 1) >= 0) {
127 double RandomNumberGenerator::NextDouble() {
128 return ((static_cast<int64_t>(Next(26)) << 27) + Next(27)) /
129 static_cast<double>(
static_cast<int64_t
>(1) << 53);
133 void RandomNumberGenerator::NextBytes(
void* buffer,
size_t buflen) {
134 for (
size_t n = 0; n < buflen; ++n) {
135 static_cast<uint8_t*
>(buffer)[n] = static_cast<uint8_t>(Next(8));
140 int RandomNumberGenerator::Next(
int bits) {
143 int64_t seed = (seed_ * kMultiplier + kAddend) & kMask;
145 return static_cast<int>(seed >> (48 - bits));
149 void RandomNumberGenerator::SetSeed(int64_t seed) {
150 seed_ = (seed ^ kMultiplier) & kMask;
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
#define LAZY_MUTEX_INITIALIZER
#define ASSERT_GE(v1, v2)
LazyStaticInstance< Mutex, DefaultConstructTrait< Mutex >, ThreadSafeInitOnceTrait >::type LazyMutex
#define ASSERT_LE(v1, v2)
#define ASSERT_LT(v1, v2)
#define ASSERT_EQ(v1, v2)
bool(* EntropySource)(unsigned char *buffer, size_t length)