forked from xtaci/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.h
35 lines (30 loc) · 751 Bytes
/
random.h
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
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* RANDOM NUMBER GENERATOR
*
* http://en.wikipedia.org/wiki/Pseudorandom_number_generator
*
******************************************************************************/
#ifndef ALGO_RANDOM_H__
#define ALGO_RANDOM_H__
#include <stdio.h>
#include <stdint.h>
namespace alg {
/**
* Linear congruential generator
* [0, 4294967295]
*/
static uint32_t LCG() {
static uint32_t a = 1664525U;
static uint32_t c = 1013904223U;
static uint32_t X0 = 0;
X0 = a*X0+c;
return X0;
}
}
#endif //