forked from GeorgeArgyros/mt_derand
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtrand.hpp
46 lines (33 loc) · 761 Bytes
/
mtrand.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef __BIT_ARRAY__
#define __BIT_ARRAY__
//#include "unroll.hpp"
#include <cstdlib>
#include <cstring>
extern "C" {
#include <stdint.h>
}
#define PHP_MT_RAND true
#define MT_RAND false
#define N (624) /* length of state vector */
#define M (397) /* a period parameter */
typedef struct {
uint32_t state[N];
uint32_t left;
uint32_t *next;
} MTState;
class MTRand
{
private:
MTState mtInfo;
bool PHPMtRand;
void mtInitialize(uint32_t);
void mtReload();
public:
MTRand(bool php = false) { PHPMtRand = php; }
void mt_srand(uint32_t);
void setState(uint32_t *s);
uint32_t mt_rand();
uint32_t php_mt_rand();
uint32_t *getState() { return mtInfo.state; }
};
#endif