refactored random subsystem
added compile-time seed support
This commit is contained in:
28
math/Random.h
Normal file
28
math/Random.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef RANDOM_H
|
||||
#define RANDOM_H
|
||||
|
||||
#include <cmath>
|
||||
#include <random>
|
||||
#include "../misc/Time.h"
|
||||
|
||||
#ifdef USE_FIXED_SEED
|
||||
#define RANDOM_SEED 1234
|
||||
#else
|
||||
#define RANDOM_SEED ( std::chrono::system_clock::now().time_since_epoch() / std::chrono::milliseconds(1) )
|
||||
#endif
|
||||
|
||||
//using RandomGenerator = std::minstd_rand;
|
||||
|
||||
class RandomGenerator : public std::minstd_rand {
|
||||
|
||||
public:
|
||||
|
||||
/** ctor with default seed */
|
||||
RandomGenerator() : std::minstd_rand(RANDOM_SEED) {;}
|
||||
|
||||
/** ctor with custom seed */
|
||||
RandomGenerator(result_type) : std::minstd_rand(RANDOM_SEED) {;}
|
||||
|
||||
};
|
||||
|
||||
#endif // RANDOM_H
|
||||
Reference in New Issue
Block a user