0% found this document useful (0 votes)
36 views2 pages

#Define MODLUS 2147483647 #Define MULT1 24112 #Define MULT2 26143

This document describes a pseudorandom number generator algorithm. It defines arrays to store the state of different random number streams. The rand() function generates the next random float for a given stream by applying a linear congruential generator twice to the stored state values, and then normalizes and returns the result. The randst() and randgt() functions allow setting and getting the current state value of a stream.

Uploaded by

Syahrul Wahyudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views2 pages

#Define MODLUS 2147483647 #Define MULT1 24112 #Define MULT2 26143

This document describes a pseudorandom number generator algorithm. It defines arrays to store the state of different random number streams. The rand() function generates the next random float for a given stream by applying a linear congruential generator twice to the stored state values, and then normalizes and returns the result. The randst() and randgt() functions allow setting and getting the current state value of a stream.

Uploaded by

Syahrul Wahyudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:

extern float rand(int stream);


extern void randst(long zset, int stream);
extern long randgt(int stream);
#define MODLUS 2147483647
#define MULT1
24112
#define MULT2
26143
static long zrng[] =
{ 0,
1973272912, 281629770,
20006270,
1933576050, 913566091, 246780520,
1511192140, 1259851944, 824064364,
75253171, 1964472944, 1202299975,
726370533, 403498145, 993232223,
1922803170, 1385516923,
76271663,
336157058, 1432650381, 1120463904,
1046574445,
68911991, 2088367019,
2122378830, 640690903, 1774806513,
78130110, 852776735, 1187867272,
1997049139, 922510944, 2045512870,
1004818771, 773686062, 403188473,
498067494, 2087759558, 493157915,
1814496276, 536444882, 1663153658,
1432404475, 619691088, 119025595,
1116780070, 277854671, 1366580350,
1053920743, 786262391, 1792203830,
1433700034, 1244184613, 1147297105,
190641742, 1645390429, 264907697,
927711160, 364849192, 2049576050,
};

1280689831,
1363774876,
150493284,
233217322,
1103205531,
413682397,
595778810,
748545416,
2132545692,
1351423507,
898585771,
372279877,
597104727,
855503735,
880802310,
1142483975,
1494667770,
539712780,
620389253,
638580085,

2096730329,
604901985,
242708531,
1911216000,
762430696,
726466604,
877722890,
622401386,
2079249579,
1645973084,
243649545,
1901633463,
1530940798,
67784357,
176192644,
2026948561,
1923011392,
1545929719,
1502074852,
547070247

/* Generate the next random number. */


float rand(int stream)
{
long zi, lowprd, hi31;
zi
lowprd
hi31
zi

zrng[stream];
(zi & 65535) * MULT1;
(zi >> 16) * MULT1 + (lowprd >> 16);
((lowprd & 65535) - MODLUS) +
((hi31 & 32767) << 16) + (hi31 >> 15);
if (zi < 0) zi += MODLUS;
lowprd = (zi & 65535) * MULT2;
hi31
= (zi >> 16) * MULT2 + (lowprd >> 16);
zi
= ((lowprd & 65535) - MODLUS) +
((hi31 & 32767) << 16) + (hi31 >> 15);
if (zi < 0) zi += MODLUS;
zrng[stream] = zi;
return ((zi >> 7 | 1) + 1)/16777216.0;
=
=
=
=

}
/* Set the current zrng for stream "stream" to zset. */
void randst(long zset, int stream)
{
zrng[stream] = zset;

59: }
60:
61: /* Return the current zrng for stream "stream". */
62:
63: long randgt(int stream)
64: {
65:
return zrng[stream];
66: }
67:
68:

You might also like