ROSE  0.11.145.0
LinearCongruentialGenerator.h
1 #ifndef ROSE_LinearCongruentialGenerator_H
2 #define ROSE_LinearCongruentialGenerator_H
3 
4 #include <stdint.h>
5 #include <stdlib.h>
6 #include "rosedll.h"
7 
9 class ROSE_UTIL_API LinearCongruentialGenerator {
10 public:
13 
15  LinearCongruentialGenerator(int seed): seed_(seed), value_(seed) {}
16 
18  void init();
19 
21  void reset() { value_=seed_; }
22 
24  void reseed(int seed) { value_ = seed_ = seed; }
25 
27  int seed() const { return seed_; }
28 
30  uint64_t again() const { return value_; }
31 
33  uint64_t max();
34 
40  uint64_t next(size_t nbits=64, size_t niter=1);
41  uint64_t operator()() { return next(); }
45  bool flip_coin();
46 
47 protected:
48  int seed_;
49  uint64_t value_;
50 };
51 
53 
54 #endif
void reset()
Reset the sequence back to the first value.
void reseed(int seed)
Start a new sequence of random values.
LinearCongruentialGenerator()
Initialize the generator with a random seed.
LinearCongruentialGenerator(int seed)
Initialize the generator with a seed.
uint64_t again() const
Return the last returned value again.
int seed() const
Return the seed for the current sequence.
Linear congruential generator.
uint64_t operator()()
Return the next value in the sequence.