| 66 |
|
#include <stdio.h> |
| 67 |
|
#include <time.h> |
| 68 |
|
#include <math.h> |
| 69 |
+ |
#include <vector> |
| 70 |
+ |
namespace oopse { |
| 71 |
|
|
| 72 |
|
class MTRand { |
| 73 |
|
// Data |
| 88 |
|
|
| 89 |
|
//Methods |
| 90 |
|
public: |
| 91 |
< |
MTRand( const uint32& oneSeed, int nstrides = 1, int stride = 0); // initialize with a simple uint32 |
| 92 |
< |
MTRand( uint32 *const bigSeed, uint32 const seedLength = N, int nstrides = 1, int stride = 0); // or an array |
| 93 |
< |
MTRand(int nstrides = 1, int stride = 0); // auto-initialize with /dev/urandom or time() and clock() |
| 91 |
> |
MTRand( const uint32& oneSeed, int nstrides, int stride); // initialize with a simple uint32 |
| 92 |
> |
MTRand( uint32 *const bigSeed, uint32 const seedLength, int nstrides, int stride); // or an array |
| 93 |
> |
MTRand(int nstrides, int stride); // auto-initialize with /dev/urandom or time() and clock() |
| 94 |
|
|
| 95 |
|
// Do NOT use for CRYPTOGRAPHY without securely hashing several returned |
| 96 |
|
// values together, otherwise the generator state can be learned after |
| 118 |
|
void seed( const uint32 oneSeed ); |
| 119 |
|
void seed( uint32 *const bigSeed, const uint32 seedLength = N ); |
| 120 |
|
void seed(); |
| 121 |
< |
|
| 121 |
> |
|
| 122 |
> |
std::vector<uint32>generateSeeds(); |
| 123 |
> |
|
| 124 |
|
// Saving and loading generator state |
| 125 |
|
void save( uint32* saveArray ) const; // to array of size SAVE |
| 126 |
|
void load( uint32 *const loadArray ); // from such array |
| 198 |
|
*/ |
| 199 |
|
inline MTRand::uint32 MTRand::randInt() { |
| 200 |
|
|
| 201 |
< |
uint32 ranNums[nstrides_]; |
| 201 |
> |
std::vector<uint32> ranNums(nstrides_); |
| 202 |
|
|
| 203 |
|
for (int i = 0; i < nstrides_; ++i) { |
| 204 |
|
ranNums[i] = rawRandInt(); |
| 293 |
|
|
| 294 |
|
inline void MTRand::seed() |
| 295 |
|
{ |
| 296 |
< |
vector<uint32> seeds; |
| 296 |
> |
std::vector<uint32> seeds; |
| 297 |
|
|
| 298 |
|
seeds = generateSeeds(); |
| 299 |
|
|
| 305 |
|
} |
| 306 |
|
|
| 307 |
|
|
| 308 |
< |
inline vector<uint32> MTRand::generateSeeds() { |
| 308 |
> |
inline std::vector<MTRand::uint32> MTRand::generateSeeds() { |
| 309 |
|
// Seed the generator with an array from /dev/urandom if available |
| 310 |
|
// Otherwise use a hash of time() and clock() values |
| 311 |
|
|
| 312 |
< |
vector<uint32> bigSeed; |
| 312 |
> |
std::vector<uint32> bigSeed; |
| 313 |
|
|
| 314 |
|
// First try getting an array from /dev/urandom |
| 315 |
|
FILE* urandom = fopen( "/dev/urandom", "rb" ); |
| 432 |
|
return is; |
| 433 |
|
} |
| 434 |
|
|
| 435 |
+ |
} |
| 436 |
|
#endif // MERSENNETWISTER_H |
| 437 |
|
|
| 438 |
|
// Change log: |