33 using namespace v8::internal;
36 static const int kMaxRuns = 12345;
37 static const int kRandomSeeds[] = {
38 -1, 1, 42, 100, 1234567890, 987654321
42 TEST(NextIntWithMaxValue) {
43 for (
unsigned n = 0; n <
ARRAY_SIZE(kRandomSeeds); ++n) {
44 RandomNumberGenerator rng(kRandomSeeds[n]);
45 for (
int max = 1; max <= kMaxRuns; ++max) {
46 int n = rng.NextInt(max);
54 TEST(NextBoolReturnsBooleanValue) {
55 for (
unsigned n = 0; n <
ARRAY_SIZE(kRandomSeeds); ++n) {
56 RandomNumberGenerator rng(kRandomSeeds[n]);
57 for (
int k = 0; k < kMaxRuns; ++k) {
58 bool b = rng.NextBool();
59 CHECK(b ==
false || b ==
true);
66 for (
unsigned n = 0; n <
ARRAY_SIZE(kRandomSeeds); ++n) {
67 RandomNumberGenerator rng(kRandomSeeds[n]);
68 for (
int k = 0; k < kMaxRuns; ++k) {
69 double d = rng.NextDouble();
77 TEST(RandomSeedFlagIsUsed) {
78 for (
unsigned n = 0; n <
ARRAY_SIZE(kRandomSeeds); ++n) {
79 FLAG_random_seed = kRandomSeeds[n];
80 RandomNumberGenerator rng1;
81 RandomNumberGenerator rng2(kRandomSeeds[n]);
82 for (
int k = 1; k <= kMaxRuns; ++k) {
84 rng1.NextBytes(&i1,
sizeof(i1));
85 rng2.NextBytes(&i2,
sizeof(i2));
87 CHECK_EQ(rng2.NextInt(), rng1.NextInt());
88 CHECK_EQ(rng2.NextInt(k), rng1.NextInt(k));
89 CHECK_EQ(rng2.NextDouble(), rng1.NextDouble());
#define CHECK_EQ(expected, value)