mirror of
https://github.com/SEPPDROID/Digital-Research-Source-Code.git
synced 2025-10-24 00:44:23 +00:00
Upload
Digital Research
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
1File: rand.c Page 1
|
||||
1 /* rand.c - kluges a random number generator with addition & overflow */
|
||||
2 #include <portab.h>
|
||||
3
|
||||
4
|
||||
5 #define NSEEDS 7
|
||||
6
|
||||
7 MLOCAL UWORD _seeds[NSEEDS] =
|
||||
8 { 0, 24213, 12345, 4622, 2143, 32010, 7942 };
|
||||
9
|
||||
10 MLOCAL WORD _seedptr=0;
|
||||
11
|
||||
12
|
||||
13 WORD srand(seed1)
|
||||
14 int seed1;
|
||||
15 {
|
||||
16 WORD ncs;
|
||||
17 _seeds[0] = seed1;
|
||||
18 for( ncs = seed1&077; ncs; ncs-- )
|
||||
19 rand();
|
||||
20 return(rand());
|
||||
21 }
|
||||
22
|
||||
23
|
||||
24 WORD rand()
|
||||
25 {
|
||||
26 UWORD tot, ii;
|
||||
27
|
||||
28 for( tot=0, ii=0; ii<NSEEDS; ii++)
|
||||
29 tot += _seeds[ii]; /* ignore overflow */
|
||||
30 if( ++_seedptr >= NSEEDS )
|
||||
31 _seedptr = 0;
|
||||
32 _seeds[_seedptr] = tot;
|
||||
33 return( tot >> 1 ); /* ignore lo bit because of addition */
|
||||
34 }
|
||||
35
|
||||
Reference in New Issue
Block a user