ROSE  0.11.96.11
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
LinearCongruentialGenerator
Linear congruential generator.
Definition: LinearCongruentialGenerator.h:9
LinearCongruentialGenerator::seed
int seed() const
Return the seed for the current sequence.
Definition: LinearCongruentialGenerator.h:27
LinearCongruentialGenerator::reset
void reset()
Reset the sequence back to the first value.
Definition: LinearCongruentialGenerator.h:21
LinearCongruentialGenerator::again
uint64_t again() const
Return the last returned value again.
Definition: LinearCongruentialGenerator.h:30
LinearCongruentialGenerator::operator()
uint64_t operator()()
Return the next value in the sequence.
Definition: LinearCongruentialGenerator.h:41
LinearCongruentialGenerator::reseed
void reseed(int seed)
Start a new sequence of random values.
Definition: LinearCongruentialGenerator.h:24
LinearCongruentialGenerator::LinearCongruentialGenerator
LinearCongruentialGenerator()
Initialize the generator with a random seed.
Definition: LinearCongruentialGenerator.h:12
LinearCongruentialGenerator::LinearCongruentialGenerator
LinearCongruentialGenerator(int seed)
Initialize the generator with a seed.
Definition: LinearCongruentialGenerator.h:15