equal
deleted
inserted
replaced
|
1 /* lran2.h |
|
2 * by Wolfram Gloger 1996. |
|
3 * |
|
4 * A small, portable pseudo-random number generator. |
|
5 */ |
|
6 |
|
7 #ifndef _LRAN2_H |
|
8 #define _LRAN2_H |
|
9 |
|
10 #define LRAN2_MAX 714025l /* constants for portable */ |
|
11 #define IA 1366l /* random number generator */ |
|
12 #define IC 150889l /* (see e.g. `Numerical Recipes') */ |
|
13 |
|
14 struct lran2_st { |
|
15 long x, y, v[97]; |
|
16 }; |
|
17 |
|
18 static void |
|
19 lran2_init(struct lran2_st* d, long seed) |
|
20 { |
|
21 long x; |
|
22 int j; |
|
23 |
|
24 x = (IC - seed) % LRAN2_MAX; |
|
25 if(x < 0) x = -x; |
|
26 for(j=0; j<97; j++) { |
|
27 x = (IA*x + IC) % LRAN2_MAX; |
|
28 d->v[j] = x; |
|
29 } |
|
30 d->x = (IA*x + IC) % LRAN2_MAX; |
|
31 d->y = d->x; |
|
32 } |
|
33 |
|
34 #ifdef __GNUC__ |
|
35 __inline__ |
|
36 #endif |
|
37 static long |
|
38 lran2(struct lran2_st* d) |
|
39 { |
|
40 int j = (d->y % 97); |
|
41 |
|
42 d->y = d->v[j]; |
|
43 d->x = (IA*d->x + IC) % LRAN2_MAX; |
|
44 d->v[j] = d->x; |
|
45 return d->y; |
|
46 } |
|
47 |
|
48 #undef IA |
|
49 #undef IC |
|
50 |
|
51 #endif |