barelymusician/common/random_test.cpp
// Tests that the same values are generated when reset with the same seed.
Tests that the same values are generated when reset with the same seed.
Tests that the same values are generated when reset with the same seed .
TEST(RandomTest, Reset) {
  const int kSeed = 1;
  const int kNumValues = 10;
  const double kMean = -0.5;
  const double kVariance = 10.0;
  Random random(kSeed);
  std::vector<double> values(kNumValues);
  for (int i = 0; i < kNumValues; ++i) {
    values[i] = random.DrawNormal(kMean, kVariance);
  }
  random.Reset(kSeed);
  for (int i = 0; i < kNumValues; ++i) {
    EXPECT_DOUBLE_EQ(random.DrawNormal(kMean, kVariance), values[i]);
  }
}
TEST ( RandomTest , Reset ) { const int kSeed = 1 ; const int kNumValues = 10 ; const double kMean = -0.5 ; const double kVariance = 10.0 ; Random random ( kSeed ) ; std :: vector < double > values ( kNumValues ) ; for ( int i = 0 ; i < kNumValues ; ++ i ) { values [ i ] = random . DrawNormal ( kMean , kVariance ) ; } random . Reset ( kSeed ) ; for ( int i = 0 ; i < kNumValues ; ++ i ) { EXPECT_DOUBLE_EQ ( random . DrawNormal ( kMean , kVariance ) , values [ i ] ) ; } }
Tests that the same values are generated when reset with the same seed.
Tests that the same values are generated when reset with the same seed .
// Generate some random values. // Reset the seed with the same value. // Validate that the same numbers are generated for the next `kNumValues`.