ROSE 0.11.145.192
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
9class ROSE_UTIL_API LinearCongruentialGenerator {
10public:
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
47protected:
48 int seed_;
49 uint64_t value_;
50};
51
53
54#endif
Linear congruential generator.
bool flip_coin()
Return a random boolean value.
LinearCongruentialGenerator(int seed)
Initialize the generator with a seed.
void init()
Random initialization.
uint64_t again() const
Return the last returned value again.
uint64_t next(size_t nbits=64, size_t niter=1)
Return the next value in the sequence.
uint64_t max()
Return the maximum possible value.
uint64_t operator()()
Return the next value in the sequence.
int seed() const
Return the seed for the current sequence.
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.