source: trunk/src/3rdparty/ptmalloc/lran2.h@ 116

Last change on this file since 116 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 837 bytes
Line 
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
14struct lran2_st {
15 long x, y, v[97];
16};
17
18static void
19lran2_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
37static long
38lran2(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
Note: See TracBrowser for help on using the repository browser.