Pseudo-random numbers/Splitmix64: Difference between revisions

m
Altered code to be more C++ idiomatic.
m (Added a new method to a class.)
m (Altered code to be more C++ idiomatic.)
Line 326:
public:
Splitmix64() { state = 0; }
Splitmix64(const uint64_t seed) : state(seed) { }
 
void seed(const uint64_t seed) {
state = seed;
}
Line 345:
private:
uint64_t state;
 
const double twoPower64 = pow(2.0, 64);
};
Line 352 ⟶ 351:
Splitmix64 random;
random.seed(1234567);
for ( intint32_t i = 0; i < 5; ++i ) {
std::cout << random.next_int() << std::endl;
}
Line 359 ⟶ 358:
Splitmix64 rand(987654321);
std::vector<uint32_t> counts(5, 0);
for ( intint32_t i = 0; i < 100'000; ++i ) {
uint32_t value = floor(rand.next_float() * 5.0);
counts[value] += 1;
}
 
for ( intint32_t i = 0; i < 5; ++i ) {
std::cout << i << ": " << counts[i] << " ";
}
915

edits