home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 Christmas / macformat-045.iso / Shareware Plus / Developers / enteract-377 / enteract-377.sit / EnterAct Stuff / hAWK project / AWK Source / RANDOM.C < prev    next >
MacBinary  |  1994-12-22  |  13.6 KB  |  [TEXT/TOPC]

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: MacBinary (archive/macBinary).

ConfidenceProgramDetectionMatch TypeSupport
66% dexvert Compact Compressed (Unix) (archive/compact) ext Supported
10% dexvert MacBinary (archive/macBinary) fallback Supported
1% dexvert Text File (text/txt) fallback Supported
100% file MacBinary II, inited, Thu Dec 22 21:28:32 1994, modified Thu Dec 22 21:28:32 1994, creator 'TOPC', type ASCII, 13253 bytes "RANDOM.C" , at 0x3445 434 bytes resource default (weak)
99% file data default
74% TrID Macintosh plain text (MacBinary) default
25% TrID MacBinary 2 default (weak)
100% lsar MacBinary default


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[TOPC]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 00 08 52 41 4e 44 4f 4d | 2e 43 00 00 00 00 00 00 |..RANDOM|.C......|
|00000010| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000040| 00 54 45 58 54 54 4f 50 | 43 01 00 00 00 00 00 00 |.TEXTTOP|C.......|
|00000050| 00 00 00 00 00 33 c5 00 | 00 01 b2 ab 1f e6 50 ab |.....3..|......P.|
|00000060| 1f e6 50 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |..P.....|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 b2 6e 00 00 |........|.....n..|
|00000080| 2f 2a 0d 20 2a 20 43 6f | 70 79 72 69 67 68 74 20 |/*. * Co|pyright |
|00000090| 28 63 29 20 31 39 38 33 | 20 52 65 67 65 6e 74 73 |(c) 1983| Regents|
|000000a0| 20 6f 66 20 74 68 65 20 | 55 6e 69 76 65 72 73 69 | of the |Universi|
|000000b0| 74 79 20 6f 66 20 43 61 | 6c 69 66 6f 72 6e 69 61 |ty of Ca|lifornia|
|000000c0| 2e 0d 20 2a 20 41 6c 6c | 20 72 69 67 68 74 73 20 |.. * All| rights |
|000000d0| 72 65 73 65 72 76 65 64 | 2e 0d 20 2a 0d 20 2a 20 |reserved|.. *. * |
|000000e0| 52 65 64 69 73 74 72 69 | 62 75 74 69 6f 6e 20 61 |Redistri|bution a|
|000000f0| 6e 64 20 75 73 65 20 69 | 6e 20 73 6f 75 72 63 65 |nd use i|n source|
|00000100| 20 61 6e 64 20 62 69 6e | 61 72 79 20 66 6f 72 6d | and bin|ary form|
|00000110| 73 20 61 72 65 20 70 65 | 72 6d 69 74 74 65 64 0d |s are pe|rmitted.|
|00000120| 20 2a 20 70 72 6f 76 69 | 64 65 64 20 74 68 61 74 | * provi|ded that|
|00000130| 20 74 68 65 20 61 62 6f | 76 65 20 63 6f 70 79 72 | the abo|ve copyr|
|00000140| 69 67 68 74 20 6e 6f 74 | 69 63 65 20 61 6e 64 20 |ight not|ice and |
|00000150| 74 68 69 73 20 70 61 72 | 61 67 72 61 70 68 20 61 |this par|agraph a|
|00000160| 72 65 0d 20 2a 20 64 75 | 70 6c 69 63 61 74 65 64 |re. * du|plicated|
|00000170| 20 69 6e 20 61 6c 6c 20 | 73 75 63 68 20 66 6f 72 | in all |such for|
|00000180| 6d 73 20 61 6e 64 20 74 | 68 61 74 20 61 6e 79 20 |ms and t|hat any |
|00000190| 64 6f 63 75 6d 65 6e 74 | 61 74 69 6f 6e 2c 0d 20 |document|ation,. |
|000001a0| 2a 20 61 64 76 65 72 74 | 69 73 69 6e 67 20 6d 61 |* advert|ising ma|
|000001b0| 74 65 72 69 61 6c 73 2c | 20 61 6e 64 20 6f 74 68 |terials,| and oth|
|000001c0| 65 72 20 6d 61 74 65 72 | 69 61 6c 73 20 72 65 6c |er mater|ials rel|
|000001d0| 61 74 65 64 20 74 6f 20 | 73 75 63 68 0d 20 2a 20 |ated to |such. * |
|000001e0| 64 69 73 74 72 69 62 75 | 74 69 6f 6e 20 61 6e 64 |distribu|tion and|
|000001f0| 20 75 73 65 20 61 63 6b | 6e 6f 77 6c 65 64 67 65 | use ack|nowledge|
|00000200| 20 74 68 61 74 20 74 68 | 65 20 73 6f 66 74 77 61 | that th|e softwa|
|00000210| 72 65 20 77 61 73 20 64 | 65 76 65 6c 6f 70 65 64 |re was d|eveloped|
|00000220| 0d 20 2a 20 62 79 20 74 | 68 65 20 55 6e 69 76 65 |. * by t|he Unive|
|00000230| 72 73 69 74 79 20 6f 66 | 20 43 61 6c 69 66 6f 72 |rsity of| Califor|
|00000240| 6e 69 61 2c 20 42 65 72 | 6b 65 6c 65 79 2e 20 20 |nia, Ber|keley. |
|00000250| 54 68 65 20 6e 61 6d 65 | 20 6f 66 20 74 68 65 0d |The name| of the.|
|00000260| 20 2a 20 55 6e 69 76 65 | 72 73 69 74 79 20 6d 61 | * Unive|rsity ma|
|00000270| 79 20 6e 6f 74 20 62 65 | 20 75 73 65 64 20 74 6f |y not be| used to|
|00000280| 20 65 6e 64 6f 72 73 65 | 20 6f 72 20 70 72 6f 6d | endorse| or prom|
|00000290| 6f 74 65 20 70 72 6f 64 | 75 63 74 73 20 64 65 72 |ote prod|ucts der|
|000002a0| 69 76 65 64 0d 20 2a 20 | 66 72 6f 6d 20 74 68 69 |ived. * |from thi|
|000002b0| 73 20 73 6f 66 74 77 61 | 72 65 20 77 69 74 68 6f |s softwa|re witho|
|000002c0| 75 74 20 73 70 65 63 69 | 66 69 63 20 70 72 69 6f |ut speci|fic prio|
|000002d0| 72 20 77 72 69 74 74 65 | 6e 20 70 65 72 6d 69 73 |r writte|n permis|
|000002e0| 73 69 6f 6e 2e 0d 20 2a | 20 54 48 49 53 20 53 4f |sion.. *| THIS SO|
|000002f0| 46 54 57 41 52 45 20 49 | 53 20 50 52 4f 56 49 44 |FTWARE I|S PROVID|
|00000300| 45 44 20 60 60 41 53 20 | 49 53 27 27 20 41 4e 44 |ED ``AS |IS'' AND|
|00000310| 20 57 49 54 48 4f 55 54 | 20 41 4e 59 20 45 58 50 | WITHOUT| ANY EXP|
|00000320| 52 45 53 53 20 4f 52 0d | 20 2a 20 49 4d 50 4c 49 |RESS OR.| * IMPLI|
|00000330| 45 44 20 57 41 52 52 41 | 4e 54 49 45 53 2c 20 49 |ED WARRA|NTIES, I|
|00000340| 4e 43 4c 55 44 49 4e 47 | 2c 20 57 49 54 48 4f 55 |NCLUDING|, WITHOU|
|00000350| 54 20 4c 49 4d 49 54 41 | 54 49 4f 4e 2c 20 54 48 |T LIMITA|TION, TH|
|00000360| 45 20 49 4d 50 4c 49 45 | 44 0d 20 2a 20 57 41 52 |E IMPLIE|D. * WAR|
|00000370| 52 41 4e 54 49 45 53 20 | 4f 46 20 4d 45 52 43 48 |RANTIES |OF MERCH|
|00000380| 41 4e 54 49 42 49 4c 49 | 54 59 20 41 4e 44 20 46 |ANTIBILI|TY AND F|
|00000390| 49 54 4e 45 53 53 20 46 | 4f 52 20 41 20 50 41 52 |ITNESS F|OR A PAR|
|000003a0| 54 49 43 55 4c 41 52 20 | 50 55 52 50 4f 53 45 2e |TICULAR |PURPOSE.|
|000003b0| 0d 20 2a 2f 0d 2f 2a 20 | 4d 61 63 20 6e 6f 74 65 |. */./* |Mac note|
|000003c0| 2c 20 6e 6f 20 63 68 61 | 6e 67 65 73 20 2a 2f 0d |, no cha|nges */.|
|000003d0| 2f 2a 0d 23 69 66 20 64 | 65 66 69 6e 65 64 28 4c |/*.#if d|efined(L|
|000003e0| 49 42 43 5f 53 43 43 53 | 29 20 26 26 20 21 64 65 |IBC_SCCS|) && !de|
|000003f0| 66 69 6e 65 64 28 6c 69 | 6e 74 29 0d 73 74 61 74 |fined(li|nt).stat|
|00000400| 69 63 20 63 68 61 72 20 | 73 63 63 73 69 64 5b 5d |ic char |sccsid[]|
|00000410| 20 3d 20 22 40 28 23 29 | 72 61 6e 64 6f 6d 2e 63 | = "@(#)|random.c|
|00000420| 09 35 2e 35 20 28 42 65 | 72 6b 65 6c 65 79 29 20 |.5.5 (Be|rkeley) |
|00000430| 37 2f 36 2f 38 38 22 3b | 0d 23 65 6e 64 69 66 20 |7/6/88";|.#endif |
|00000440| 0d 2d 2d 20 4c 49 42 43 | 5f 53 43 43 53 20 61 6e |.-- LIBC|_SCCS an|
|00000450| 64 20 6e 6f 74 20 6c 69 | 6e 74 20 2a 2f 0d 0d 23 |d not li|nt */..#|
|00000460| 69 6e 63 6c 75 64 65 20 | 3c 73 74 64 69 6f 2e 68 |include |<stdio.h|
|00000470| 3e 0d 73 68 6f 72 74 20 | 73 72 61 6e 64 6f 6d 28 |>.short |srandom(|
|00000480| 75 6e 73 69 67 6e 65 64 | 20 78 20 29 3b 0d 63 68 |unsigned| x );.ch|
|00000490| 61 72 20 20 2a 69 6e 69 | 74 73 74 61 74 65 28 75 |ar *ini|tstate(u|
|000004a0| 6e 73 69 67 6e 65 64 20 | 73 65 65 64 2c 20 63 68 |nsigned |seed, ch|
|000004b0| 61 72 20 2a 61 72 67 5f | 73 74 61 74 65 2c 20 73 |ar *arg_|state, s|
|000004c0| 68 6f 72 74 20 6e 20 29 | 3b 0d 63 68 61 72 20 20 |hort n )|;.char |
|000004d0| 2a 73 65 74 73 74 61 74 | 65 28 63 68 61 72 20 2a |*setstat|e(char *|
|000004e0| 61 72 67 5f 73 74 61 74 | 65 20 29 3b 0d 6c 6f 6e |arg_stat|e );.lon|
|000004f0| 67 20 72 61 6e 64 6f 6d | 28 76 6f 69 64 29 3b 0d |g random|(void);.|
|00000500| 0d 2f 2a 0d 20 2a 20 72 | 61 6e 64 6f 6d 2e 63 3a |./*. * r|andom.c:|
|00000510| 0d 20 2a 20 41 6e 20 69 | 6d 70 72 6f 76 65 64 20 |. * An i|mproved |
|00000520| 72 61 6e 64 6f 6d 20 6e | 75 6d 62 65 72 20 67 65 |random n|umber ge|
|00000530| 6e 65 72 61 74 69 6f 6e | 20 70 61 63 6b 61 67 65 |neration| package|
|00000540| 2e 20 20 49 6e 20 61 64 | 64 69 74 69 6f 6e 20 74 |. In ad|dition t|
|00000550| 6f 20 74 68 65 20 73 74 | 61 6e 64 61 72 64 0d 20 |o the st|andard. |
|00000560| 2a 20 72 61 6e 64 28 29 | 2f 73 72 61 6e 64 28 29 |* rand()|/srand()|
|00000570| 20 6c 69 6b 65 20 69 6e | 74 65 72 66 61 63 65 2c | like in|terface,|
|00000580| 20 74 68 69 73 20 70 61 | 63 6b 61 67 65 20 61 6c | this pa|ckage al|
|00000590| 73 6f 20 68 61 73 20 61 | 20 73 70 65 63 69 61 6c |so has a| special|
|000005a0| 20 73 74 61 74 65 20 69 | 6e 66 6f 0d 20 2a 20 69 | state i|nfo. * i|
|000005b0| 6e 74 65 72 66 61 63 65 | 2e 20 20 54 68 65 20 69 |nterface|. The i|
|000005c0| 6e 69 74 73 74 61 74 65 | 28 29 20 72 6f 75 74 69 |nitstate|() routi|
|000005d0| 6e 65 20 69 73 20 63 61 | 6c 6c 65 64 20 77 69 74 |ne is ca|lled wit|
|000005e0| 68 20 61 20 73 65 65 64 | 2c 20 61 6e 20 61 72 72 |h a seed|, an arr|
|000005f0| 61 79 20 6f 66 0d 20 2a | 20 62 79 74 65 73 2c 20 |ay of. *| bytes, |
|00000600| 61 6e 64 20 61 20 63 6f | 75 6e 74 20 6f 66 20 68 |and a co|unt of h|
|00000610| 6f 77 20 6d 61 6e 79 20 | 62 79 74 65 73 20 61 72 |ow many |bytes ar|
|00000620| 65 20 62 65 69 6e 67 20 | 70 61 73 73 65 64 20 69 |e being |passed i|
|00000630| 6e 3b 20 74 68 69 73 20 | 61 72 72 61 79 20 69 73 |n; this |array is|
|00000640| 20 74 68 65 6e 0d 20 2a | 20 69 6e 69 74 69 61 6c | then. *| initial|
|00000650| 69 7a 65 64 20 74 6f 20 | 63 6f 6e 74 61 69 6e 20 |ized to |contain |
|00000660| 69 6e 66 6f 72 6d 61 74 | 69 6f 6e 20 66 6f 72 20 |informat|ion for |
|00000670| 72 61 6e 64 6f 6d 20 6e | 75 6d 62 65 72 20 67 65 |random n|umber ge|
|00000680| 6e 65 72 61 74 69 6f 6e | 20 77 69 74 68 20 74 68 |neration| with th|
|00000690| 61 74 0d 20 2a 20 6d 75 | 63 68 20 73 74 61 74 65 |at. * mu|ch state|
|000006a0| 20 69 6e 66 6f 72 6d 61 | 74 69 6f 6e 2e 20 20 47 | informa|tion. G|
|000006b0| 6f 6f 64 20 73 69 7a 65 | 73 20 66 6f 72 20 74 68 |ood size|s for th|
|000006c0| 65 20 61 6d 6f 75 6e 74 | 20 6f 66 20 73 74 61 74 |e amount| of stat|
|000006d0| 65 20 69 6e 66 6f 72 6d | 61 74 69 6f 6e 20 61 72 |e inform|ation ar|
|000006e0| 65 0d 20 2a 20 33 32 2c | 20 36 34 2c 20 31 32 38 |e. * 32,| 64, 128|
|000006f0| 2c 20 61 6e 64 20 32 35 | 36 20 62 79 74 65 73 2e |, and 25|6 bytes.|
|00000700| 20 20 54 68 65 20 73 74 | 61 74 65 20 63 61 6e 20 | The st|ate can |
|00000710| 62 65 20 73 77 69 74 63 | 68 65 64 20 62 79 20 63 |be switc|hed by c|
|00000720| 61 6c 6c 69 6e 67 20 74 | 68 65 0d 20 2a 20 73 65 |alling t|he. * se|
|00000730| 74 73 74 61 74 65 28 29 | 20 72 6f 75 74 69 6e 65 |tstate()| routine|
|00000740| 20 77 69 74 68 20 74 68 | 65 20 73 61 6d 65 20 61 | with th|e same a|
|00000750| 72 72 61 79 20 61 73 20 | 77 61 73 20 69 6e 69 74 |rray as |was init|
|00000760| 69 61 6c 6c 69 7a 65 64 | 20 77 69 74 68 20 69 6e |iallized| with in|
|00000770| 69 74 73 74 61 74 65 28 | 29 2e 0d 20 2a 20 42 79 |itstate(|).. * By|
|00000780| 20 64 65 66 61 75 6c 74 | 2c 20 74 68 65 20 70 61 | default|, the pa|
|00000790| 63 6b 61 67 65 20 72 75 | 6e 73 20 77 69 74 68 20 |ckage ru|ns with |
|000007a0| 31 32 38 20 62 79 74 65 | 73 20 6f 66 20 73 74 61 |128 byte|s of sta|
|000007b0| 74 65 20 69 6e 66 6f 72 | 6d 61 74 69 6f 6e 20 61 |te infor|mation a|
|000007c0| 6e 64 0d 20 2a 20 67 65 | 6e 65 72 61 74 65 73 20 |nd. * ge|nerates |
|000007d0| 66 61 72 20 62 65 74 74 | 65 72 20 72 61 6e 64 6f |far bett|er rando|
|000007e0| 6d 20 6e 75 6d 62 65 72 | 73 20 74 68 61 6e 20 61 |m number|s than a|
|000007f0| 20 6c 69 6e 65 61 72 20 | 63 6f 6e 67 72 75 65 6e | linear |congruen|
|00000800| 74 69 61 6c 20 67 65 6e | 65 72 61 74 6f 72 2e 0d |tial gen|erator..|
|00000810| 20 2a 20 49 66 20 74 68 | 65 20 61 6d 6f 75 6e 74 | * If th|e amount|
|00000820| 20 6f 66 20 73 74 61 74 | 65 20 69 6e 66 6f 72 6d | of stat|e inform|
|00000830| 61 74 69 6f 6e 20 69 73 | 20 6c 65 73 73 20 74 68 |ation is| less th|
|00000840| 61 6e 20 33 32 20 62 79 | 74 65 73 2c 20 61 20 73 |an 32 by|tes, a s|
|00000850| 69 6d 70 6c 65 20 6c 69 | 6e 65 61 72 0d 20 2a 20 |imple li|near. * |
|00000860| 63 6f 6e 67 72 75 65 6e | 74 69 61 6c 20 52 2e 4e |congruen|tial R.N|
|00000870| 2e 47 2e 20 69 73 20 75 | 73 65 64 2e 0d 20 2a 20 |.G. is u|sed.. * |
|00000880| 49 6e 74 65 72 6e 61 6c | 6c 79 2c 20 74 68 65 20 |Internal|ly, the |
|00000890| 73 74 61 74 65 20 69 6e | 66 6f 72 6d 61 74 69 6f |state in|formatio|
|000008a0| 6e 20 69 73 20 74 72 65 | 61 74 65 64 20 61 73 20 |n is tre|ated as |
|000008b0| 61 6e 20 61 72 72 61 79 | 20 6f 66 20 6c 6f 6e 67 |an array| of long|
|000008c0| 73 3b 20 74 68 65 0d 20 | 2a 20 7a 65 72 6f 65 74 |s; the. |* zeroet|
|000008d0| 68 20 65 6c 65 6d 65 6e | 74 20 6f 66 20 74 68 65 |h elemen|t of the|
|000008e0| 20 61 72 72 61 79 20 69 | 73 20 74 68 65 20 74 79 | array i|s the ty|
|000008f0| 70 65 20 6f 66 20 52 2e | 4e 2e 47 2e 20 62 65 69 |pe of R.|N.G. bei|
|00000900| 6e 67 20 75 73 65 64 20 | 28 73 6d 61 6c 6c 0d 20 |ng used |(small. |
|00000910| 2a 20 69 6e 74 65 67 65 | 72 29 3b 20 74 68 65 20 |* intege|r); the |
|00000920| 72 65 6d 61 69 6e 64 65 | 72 20 6f 66 20 74 68 65 |remainde|r of the|
|00000930| 20 61 72 72 61 79 20 69 | 73 20 74 68 65 20 73 74 | array i|s the st|
|00000940| 61 74 65 20 69 6e 66 6f | 72 6d 61 74 69 6f 6e 20 |ate info|rmation |
|00000950| 66 6f 72 20 74 68 65 0d | 20 2a 20 52 2e 4e 2e 47 |for the.| * R.N.G|
|00000960| 2e 20 20 54 68 75 73 2c | 20 33 32 20 62 79 74 65 |. Thus,| 32 byte|
|00000970| 73 20 6f 66 20 73 74 61 | 74 65 20 69 6e 66 6f 72 |s of sta|te infor|
|00000980| 6d 61 74 69 6f 6e 20 77 | 69 6c 6c 20 67 69 76 65 |mation w|ill give|
|00000990| 20 37 20 6c 6f 6e 67 73 | 20 77 6f 72 74 68 20 6f | 7 longs| worth o|
|000009a0| 66 0d 20 2a 20 73 74 61 | 74 65 20 69 6e 66 6f 72 |f. * sta|te infor|
|000009b0| 6d 61 74 69 6f 6e 2c 20 | 77 68 69 63 68 20 77 69 |mation, |which wi|
|000009c0| 6c 6c 20 61 6c 6c 6f 77 | 20 61 20 64 65 67 72 65 |ll allow| a degre|
|000009d0| 65 20 73 65 76 65 6e 20 | 70 6f 6c 79 6e 6f 6d 69 |e seven |polynomi|
|000009e0| 61 6c 2e 20 20 28 4e 6f | 74 65 3a 20 74 68 65 0d |al. (No|te: the.|
|000009f0| 20 2a 20 7a 65 72 6f 65 | 74 68 20 77 6f 72 64 20 | * zeroe|th word |
|00000a00| 6f 66 20 73 74 61 74 65 | 20 69 6e 66 6f 72 6d 61 |of state| informa|
|00000a10| 74 69 6f 6e 20 61 6c 73 | 6f 20 68 61 73 20 73 6f |tion als|o has so|
|00000a20| 6d 65 20 6f 74 68 65 72 | 20 69 6e 66 6f 72 6d 61 |me other| informa|
|00000a30| 74 69 6f 6e 20 73 74 6f | 72 65 64 0d 20 2a 20 69 |tion sto|red. * i|
|00000a40| 6e 20 69 74 20 2d 2d 20 | 73 65 65 20 73 65 74 73 |n it -- |see sets|
|00000a50| 74 61 74 65 28 29 20 66 | 6f 72 20 64 65 74 61 69 |tate() f|or detai|
|00000a60| 6c 73 29 2e 0d 20 2a 20 | 54 68 65 20 72 61 6e 64 |ls).. * |The rand|
|00000a70| 6f 6d 20 6e 75 6d 62 65 | 72 20 67 65 6e 65 72 61 |om numbe|r genera|
|00000a80| 74 69 6f 6e 20 74 65 63 | 68 6e 69 71 75 65 20 69 |tion tec|hnique i|
|00000a90| 73 20 61 20 6c 69 6e 65 | 61 72 20 66 65 65 64 62 |s a line|ar feedb|
|00000aa0| 61 63 6b 20 73 68 69 66 | 74 20 72 65 67 69 73 74 |ack shif|t regist|
|00000ab0| 65 72 0d 20 2a 20 61 70 | 70 72 6f 61 63 68 2c 20 |er. * ap|proach, |
|00000ac0| 65 6d 70 6c 6f 79 69 6e | 67 20 74 72 69 6e 6f 6d |employin|g trinom|
|00000ad0| 69 61 6c 73 20 28 73 69 | 6e 63 65 20 74 68 65 72 |ials (si|nce ther|
|00000ae0| 65 20 61 72 65 20 66 65 | 77 65 72 20 74 65 72 6d |e are fe|wer term|
|00000af0| 73 20 74 6f 20 73 75 6d | 20 75 70 20 74 68 61 74 |s to sum| up that|
|00000b00| 0d 20 2a 20 77 61 79 29 | 2e 20 20 49 6e 20 74 68 |. * way)|. In th|
|00000b10| 69 73 20 61 70 70 72 6f | 61 63 68 2c 20 74 68 65 |is appro|ach, the|
|00000b20| 20 6c 65 61 73 74 20 73 | 69 67 6e 69 66 69 63 61 | least s|ignifica|
|00000b30| 6e 74 20 62 69 74 20 6f | 66 20 61 6c 6c 20 74 68 |nt bit o|f all th|
|00000b40| 65 20 6e 75 6d 62 65 72 | 73 20 69 6e 0d 20 2a 20 |e number|s in. * |
|00000b50| 74 68 65 20 73 74 61 74 | 65 20 74 61 62 6c 65 20 |the stat|e table |
|00000b60| 77 69 6c 6c 20 61 63 74 | 20 61 73 20 61 20 6c 69 |will act| as a li|
|00000b70| 6e 65 61 72 20 66 65 65 | 64 62 61 63 6b 20 73 68 |near fee|dback sh|
|00000b80| 69 66 74 20 72 65 67 69 | 73 74 65 72 2c 20 61 6e |ift regi|ster, an|
|00000b90| 64 20 77 69 6c 6c 20 68 | 61 76 65 0d 20 2a 20 70 |d will h|ave. * p|
|00000ba0| 65 72 69 6f 64 20 32 5e | 64 65 67 20 2d 20 31 20 |eriod 2^|deg - 1 |
|00000bb0| 28 77 68 65 72 65 20 64 | 65 67 20 69 73 20 74 68 |(where d|eg is th|
|00000bc0| 65 20 64 65 67 72 65 65 | 20 6f 66 20 74 68 65 20 |e degree| of the |
|00000bd0| 70 6f 6c 79 6e 6f 6d 69 | 61 6c 20 62 65 69 6e 67 |polynomi|al being|
|00000be0| 20 75 73 65 64 2c 0d 20 | 2a 20 61 73 73 75 6d 69 | used,. |* assumi|
|00000bf0| 6e 67 20 74 68 61 74 20 | 74 68 65 20 70 6f 6c 79 |ng that |the poly|
|00000c00| 6e 6f 6d 69 61 6c 20 69 | 73 20 69 72 72 65 64 75 |nomial i|s irredu|
|00000c10| 63 69 62 6c 65 20 61 6e | 64 20 70 72 69 6d 69 74 |cible an|d primit|
|00000c20| 69 76 65 29 2e 20 20 54 | 68 65 20 68 69 67 68 65 |ive). T|he highe|
|00000c30| 72 0d 20 2a 20 6f 72 64 | 65 72 20 62 69 74 73 20 |r. * ord|er bits |
|00000c40| 77 69 6c 6c 20 68 61 76 | 65 20 6c 6f 6e 67 65 72 |will hav|e longer|
|00000c50| 20 70 65 72 69 6f 64 73 | 2c 20 73 69 6e 63 65 20 | periods|, since |
|00000c60| 74 68 65 69 72 20 76 61 | 6c 75 65 73 20 61 72 65 |their va|lues are|
|00000c70| 20 61 6c 73 6f 20 69 6e | 66 6c 75 65 6e 63 65 64 | also in|fluenced|
|00000c80| 0d 20 2a 20 62 79 20 70 | 73 65 75 64 6f 2d 72 61 |. * by p|seudo-ra|
|00000c90| 6e 64 6f 6d 20 63 61 72 | 72 69 65 73 20 6f 75 74 |ndom car|ries out|
|00000ca0| 20 6f 66 20 74 68 65 20 | 6c 6f 77 65 72 20 62 69 | of the |lower bi|
|00000cb0| 74 73 2e 20 20 54 68 65 | 20 74 6f 74 61 6c 20 70 |ts. The| total p|
|00000cc0| 65 72 69 6f 64 20 6f 66 | 20 74 68 65 0d 20 2a 20 |eriod of| the. * |
|00000cd0| 67 65 6e 65 72 61 74 6f | 72 20 69 73 20 61 70 70 |generato|r is app|
|00000ce0| 72 6f 78 69 6d 61 74 65 | 6c 79 20 64 65 67 2a 28 |roximate|ly deg*(|
|00000cf0| 32 2a 2a 64 65 67 20 2d | 20 31 29 3b 20 74 68 75 |2**deg -| 1); thu|
|00000d00| 73 20 64 6f 75 62 6c 69 | 6e 67 20 74 68 65 20 61 |s doubli|ng the a|
|00000d10| 6d 6f 75 6e 74 20 6f 66 | 0d 20 2a 20 73 74 61 74 |mount of|. * stat|
|00000d20| 65 20 69 6e 66 6f 72 6d | 61 74 69 6f 6e 20 68 61 |e inform|ation ha|
|00000d30| 73 20 61 20 76 61 73 74 | 20 69 6e 66 6c 75 65 6e |s a vast| influen|
|00000d40| 63 65 20 6f 6e 20 74 68 | 65 20 70 65 72 69 6f 64 |ce on th|e period|
|00000d50| 20 6f 66 20 74 68 65 20 | 67 65 6e 65 72 61 74 6f | of the |generato|
|00000d60| 72 2e 0d 20 2a 20 4e 6f | 74 65 3a 20 74 68 65 20 |r.. * No|te: the |
|00000d70| 64 65 67 2a 28 32 2a 2a | 64 65 67 20 2d 20 31 29 |deg*(2**|deg - 1)|
|00000d80| 20 69 73 20 61 6e 20 61 | 70 70 72 6f 78 69 6d 61 | is an a|pproxima|
|00000d90| 74 69 6f 6e 20 6f 6e 6c | 79 20 67 6f 6f 64 20 66 |tion onl|y good f|
|00000da0| 6f 72 20 6c 61 72 67 65 | 20 64 65 67 2c 0d 20 2a |or large| deg,. *|
|00000db0| 20 77 68 65 6e 20 74 68 | 65 20 70 65 72 69 6f 64 | when th|e period|
|00000dc0| 20 6f 66 20 74 68 65 20 | 73 68 69 66 74 20 72 65 | of the |shift re|
|00000dd0| 67 69 73 74 65 72 20 69 | 73 20 74 68 65 20 64 6f |gister i|s the do|
|00000de0| 6d 69 6e 61 6e 74 20 66 | 61 63 74 6f 72 2e 20 20 |minant f|actor. |
|00000df0| 57 69 74 68 20 64 65 67 | 0d 20 2a 20 65 71 75 61 |With deg|. * equa|
|00000e00| 6c 20 74 6f 20 73 65 76 | 65 6e 2c 20 74 68 65 20 |l to sev|en, the |
|00000e10| 70 65 72 69 6f 64 20 69 | 73 20 61 63 74 75 61 6c |period i|s actual|
|00000e20| 6c 79 20 6d 75 63 68 20 | 6c 6f 6e 67 65 72 20 74 |ly much |longer t|
|00000e30| 68 61 6e 20 74 68 65 20 | 37 2a 28 32 2a 2a 37 20 |han the |7*(2**7 |
|00000e40| 2d 20 31 29 0d 20 2a 20 | 70 72 65 64 69 63 74 65 |- 1). * |predicte|
|00000e50| 64 20 62 79 20 74 68 69 | 73 20 66 6f 72 6d 75 6c |d by thi|s formul|
|00000e60| 61 2e 0d 20 2a 2f 0d 0d | 0d 0d 2f 2a 0d 20 2a 20 |a.. */..|../*. * |
|00000e70| 46 6f 72 20 65 61 63 68 | 20 6f 66 20 74 68 65 20 |For each| of the |
|00000e80| 63 75 72 72 65 6e 74 6c | 79 20 73 75 70 70 6f 72 |currentl|y suppor|
|00000e90| 74 65 64 20 72 61 6e 64 | 6f 6d 20 6e 75 6d 62 65 |ted rand|om numbe|
|00000ea0| 72 20 67 65 6e 65 72 61 | 74 6f 72 73 2c 20 77 65 |r genera|tors, we|
|00000eb0| 20 68 61 76 65 20 61 0d | 20 2a 20 62 72 65 61 6b | have a.| * break|
|00000ec0| 20 76 61 6c 75 65 20 6f | 6e 20 74 68 65 20 61 6d | value o|n the am|
|00000ed0| 6f 75 6e 74 20 6f 66 20 | 73 74 61 74 65 20 69 6e |ount of |state in|
|00000ee0| 66 6f 72 6d 61 74 69 6f | 6e 20 28 79 6f 75 20 6e |formatio|n (you n|
|00000ef0| 65 65 64 20 61 74 20 6c | 65 61 73 74 20 74 68 69 |eed at l|east thi|
|00000f00| 73 0d 20 2a 20 6d 61 6e | 79 20 62 79 74 65 73 20 |s. * man|y bytes |
|00000f10| 6f 66 20 73 74 61 74 65 | 20 69 6e 66 6f 20 74 6f |of state| info to|
|00000f20| 20 73 75 70 70 6f 72 74 | 20 74 68 69 73 20 72 61 | support| this ra|
|00000f30| 6e 64 6f 6d 20 6e 75 6d | 62 65 72 20 67 65 6e 65 |ndom num|ber gene|
|00000f40| 72 61 74 6f 72 29 2c 20 | 61 20 64 65 67 72 65 65 |rator), |a degree|
|00000f50| 0d 20 2a 20 66 6f 72 20 | 74 68 65 20 70 6f 6c 79 |. * for |the poly|
|00000f60| 6e 6f 6d 69 61 6c 20 28 | 61 63 74 75 61 6c 6c 79 |nomial (|actually|
|00000f70| 20 61 20 74 72 69 6e 6f | 6d 69 61 6c 29 20 74 68 | a trino|mial) th|
|00000f80| 61 74 20 74 68 65 20 52 | 2e 4e 2e 47 2e 20 69 73 |at the R|.N.G. is|
|00000f90| 20 62 61 73 65 64 20 6f | 6e 2c 20 61 6e 64 0d 20 | based o|n, and. |
|00000fa0| 2a 20 74 68 65 20 73 65 | 70 61 72 61 74 69 6f 6e |* the se|paration|
|00000fb0| 20 62 65 74 77 65 65 6e | 20 74 68 65 20 74 77 6f | between| the two|
|00000fc0| 20 6c 6f 77 65 72 20 6f | 72 64 65 72 20 63 6f 65 | lower o|rder coe|
|00000fd0| 66 66 69 63 69 65 6e 74 | 73 20 6f 66 20 74 68 65 |fficient|s of the|
|00000fe0| 20 74 72 69 6e 6f 6d 69 | 61 6c 2e 0d 20 2a 2f 0d | trinomi|al.. */.|
|00000ff0| 0d 23 64 65 66 69 6e 65 | 09 09 54 59 50 45 5f 30 |.#define|..TYPE_0|
|00001000| 09 09 30 09 09 2f 2a 20 | 6c 69 6e 65 61 72 20 63 |..0../* |linear c|
|00001010| 6f 6e 67 72 75 65 6e 74 | 69 61 6c 20 2a 2f 0d 23 |ongruent|ial */.#|
|00001020| 64 65 66 69 6e 65 09 09 | 42 52 45 41 4b 5f 30 09 |define..|BREAK_0.|
|00001030| 09 38 0d 23 64 65 66 69 | 6e 65 09 09 44 45 47 5f |.8.#defi|ne..DEG_|
|00001040| 30 09 09 30 0d 23 64 65 | 66 69 6e 65 09 09 53 45 |0..0.#de|fine..SE|
|00001050| 50 5f 30 09 09 30 0d 0d | 23 64 65 66 69 6e 65 09 |P_0..0..|#define.|
|00001060| 09 54 59 50 45 5f 31 09 | 09 31 09 09 2f 2a 20 78 |.TYPE_1.|.1../* x|
|00001070| 2a 2a 37 20 2b 20 78 2a | 2a 33 20 2b 20 31 20 2a |**7 + x*|*3 + 1 *|
|00001080| 2f 0d 23 64 65 66 69 6e | 65 09 09 42 52 45 41 4b |/.#defin|e..BREAK|
|00001090| 5f 31 09 09 33 32 0d 23 | 64 65 66 69 6e 65 09 09 |_1..32.#|define..|
|000010a0| 44 45 47 5f 31 09 09 37 | 0d 23 64 65 66 69 6e 65 |DEG_1..7|.#define|
|000010b0| 09 09 53 45 50 5f 31 09 | 09 33 0d 0d 23 64 65 66 |..SEP_1.|.3..#def|
|000010c0| 69 6e 65 09 09 54 59 50 | 45 5f 32 09 09 32 09 09 |ine..TYP|E_2..2..|
|000010d0| 2f 2a 20 78 2a 2a 31 35 | 20 2b 20 78 20 2b 20 31 |/* x**15| + x + 1|
|000010e0| 20 2a 2f 0d 23 64 65 66 | 69 6e 65 09 09 42 52 45 | */.#def|ine..BRE|
|000010f0| 41 4b 5f 32 09 09 36 34 | 0d 23 64 65 66 69 6e 65 |AK_2..64|.#define|
|00001100| 09 09 44 45 47 5f 32 09 | 09 31 35 0d 23 64 65 66 |..DEG_2.|.15.#def|
|00001110| 69 6e 65 09 09 53 45 50 | 5f 32 09 09 31 0d 0d 23 |ine..SEP|_2..1..#|
|00001120| 64 65 66 69 6e 65 09 09 | 54 59 50 45 5f 33 09 09 |define..|TYPE_3..|
|00001130| 33 09 09 2f 2a 20 78 2a | 2a 33 31 20 2b 20 78 2a |3../* x*|*31 + x*|
|00001140| 2a 33 20 2b 20 31 20 2a | 2f 0d 23 64 65 66 69 6e |*3 + 1 *|/.#defin|
|00001150| 65 09 09 42 52 45 41 4b | 5f 33 09 09 31 32 38 0d |e..BREAK|_3..128.|
|00001160| 23 64 65 66 69 6e 65 09 | 09 44 45 47 5f 33 09 09 |#define.|.DEG_3..|
|00001170| 33 31 0d 23 64 65 66 69 | 6e 65 09 09 53 45 50 5f |31.#defi|ne..SEP_|
|00001180| 33 09 09 33 0d 0d 23 64 | 65 66 69 6e 65 09 09 54 |3..3..#d|efine..T|
|00001190| 59 50 45 5f 34 09 09 34 | 09 09 2f 2a 20 78 2a 2a |YPE_4..4|../* x**|
|000011a0| 36 33 20 2b 20 78 20 2b | 20 31 20 2a 2f 0d 23 64 |63 + x +| 1 */.#d|
|000011b0| 65 66 69 6e 65 09 09 42 | 52 45 41 4b 5f 34 09 09 |efine..B|REAK_4..|
|000011c0| 32 35 36 0d 23 64 65 66 | 69 6e 65 09 09 44 45 47 |256.#def|ine..DEG|
|000011d0| 5f 34 09 09 36 33 0d 23 | 64 65 66 69 6e 65 09 09 |_4..63.#|define..|
|000011e0| 53 45 50 5f 34 09 09 31 | 0d 0d 0d 2f 2a 0d 20 2a |SEP_4..1|.../*. *|
|000011f0| 20 41 72 72 61 79 20 76 | 65 72 73 69 6f 6e 73 20 | Array v|ersions |
|00001200| 6f 66 20 74 68 65 20 61 | 62 6f 76 65 20 69 6e 66 |of the a|bove inf|
|00001210| 6f 72 6d 61 74 69 6f 6e | 20 74 6f 20 6d 61 6b 65 |ormation| to make|
|00001220| 20 63 6f 64 65 20 72 75 | 6e 20 66 61 73 74 65 72 | code ru|n faster|
|00001230| 20 2d 2d 20 72 65 6c 69 | 65 73 0d 20 2a 20 6f 6e | -- reli|es. * on|
|00001240| 20 66 61 63 74 20 74 68 | 61 74 20 54 59 50 45 5f | fact th|at TYPE_|
|00001250| 69 20 3d 3d 20 69 2e 0d | 20 2a 2f 0d 0d 23 64 65 |i == i..| */..#de|
|00001260| 66 69 6e 65 09 09 4d 41 | 58 5f 54 59 50 45 53 09 |fine..MA|X_TYPES.|
|00001270| 35 09 09 2f 2a 20 6d 61 | 78 20 6e 75 6d 62 65 72 |5../* ma|x number|
|00001280| 20 6f 66 20 74 79 70 65 | 73 20 61 62 6f 76 65 20 | of type|s above |
|00001290| 2a 2f 0d 0d 73 74 61 74 | 69 63 20 20 73 68 6f 72 |*/..stat|ic shor|
|000012a0| 74 09 09 64 65 67 72 65 | 65 73 5b 20 4d 41 58 5f |t..degre|es[ MAX_|
|000012b0| 54 59 50 45 53 20 5d 09 | 3d 20 7b 20 44 45 47 5f |TYPES ].|= { DEG_|
|000012c0| 30 2c 20 44 45 47 5f 31 | 2c 20 44 45 47 5f 32 2c |0, DEG_1|, DEG_2,|
|000012d0| 0d 09 09 09 09 09 09 09 | 09 44 45 47 5f 33 2c 20 |........|.DEG_3, |
|000012e0| 44 45 47 5f 34 20 7d 3b | 0d 0d 73 74 61 74 69 63 |DEG_4 };|..static|
|000012f0| 20 20 73 68 6f 72 74 09 | 09 73 65 70 73 5b 20 4d | short.|.seps[ M|
|00001300| 41 58 5f 54 59 50 45 53 | 20 5d 09 3d 20 7b 20 53 |AX_TYPES| ].= { S|
|00001310| 45 50 5f 30 2c 20 53 45 | 50 5f 31 2c 20 53 45 50 |EP_0, SE|P_1, SEP|
|00001320| 5f 32 2c 0d 09 09 09 09 | 09 09 09 09 53 45 50 5f |_2,.....|....SEP_|
|00001330| 33 2c 20 53 45 50 5f 34 | 20 7d 3b 0d 0d 0d 0d 2f |3, SEP_4| };..../|
|00001340| 2a 0d 20 2a 20 49 6e 69 | 74 69 61 6c 6c 79 2c 20 |*. * Ini|tially, |
|00001350| 65 76 65 72 79 74 68 69 | 6e 67 20 69 73 20 73 65 |everythi|ng is se|
|00001360| 74 20 75 70 20 61 73 20 | 69 66 20 66 72 6f 6d 20 |t up as |if from |
|00001370| 3a 0d 20 2a 09 09 69 6e | 69 74 73 74 61 74 65 28 |:. *..in|itstate(|
|00001380| 20 31 2c 20 26 72 61 6e | 64 74 62 6c 2c 20 31 32 | 1, &ran|dtbl, 12|
|00001390| 38 20 29 3b 0d 20 2a 20 | 4e 6f 74 65 20 74 68 61 |8 );. * |Note tha|
|000013a0| 74 20 74 68 69 73 20 69 | 6e 69 74 69 61 6c 69 7a |t this i|nitializ|
|000013b0| 61 74 69 6f 6e 20 74 61 | 6b 65 73 20 61 64 76 61 |ation ta|kes adva|
|000013c0| 6e 74 61 67 65 20 6f 66 | 20 74 68 65 20 66 61 63 |ntage of| the fac|
|000013d0| 74 20 74 68 61 74 20 73 | 72 61 6e 64 6f 6d 28 29 |t that s|random()|
|000013e0| 0d 20 2a 20 61 64 76 61 | 6e 63 65 73 20 74 68 65 |. * adva|nces the|
|000013f0| 20 66 72 6f 6e 74 20 61 | 6e 64 20 72 65 61 72 20 | front a|nd rear |
|00001400| 70 6f 69 6e 74 65 72 73 | 20 31 30 2a 72 61 6e 64 |pointers| 10*rand|
|00001410| 5f 64 65 67 20 74 69 6d | 65 73 2c 20 61 6e 64 20 |_deg tim|es, and |
|00001420| 68 65 6e 63 65 20 74 68 | 65 0d 20 2a 20 72 65 61 |hence th|e. * rea|
|00001430| 72 20 70 6f 69 6e 74 65 | 72 20 77 68 69 63 68 20 |r pointe|r which |
|00001440| 73 74 61 72 74 73 20 61 | 74 20 30 20 77 69 6c 6c |starts a|t 0 will|
|00001450| 20 61 6c 73 6f 20 65 6e | 64 20 75 70 20 61 74 20 | also en|d up at |
|00001460| 7a 65 72 6f 3b 20 74 68 | 75 73 20 74 68 65 20 7a |zero; th|us the z|
|00001470| 65 72 6f 65 74 68 0d 20 | 2a 20 65 6c 65 6d 65 6e |eroeth. |* elemen|
|00001480| 74 20 6f 66 20 74 68 65 | 20 73 74 61 74 65 20 69 |t of the| state i|
|00001490| 6e 66 6f 72 6d 61 74 69 | 6f 6e 2c 20 77 68 69 63 |nformati|on, whic|
|000014a0| 68 20 63 6f 6e 74 61 69 | 6e 73 20 69 6e 66 6f 20 |h contai|ns info |
|000014b0| 61 62 6f 75 74 20 74 68 | 65 20 63 75 72 72 65 6e |about th|e curren|
|000014c0| 74 0d 20 2a 20 70 6f 73 | 69 74 69 6f 6e 20 6f 66 |t. * pos|ition of|
|000014d0| 20 74 68 65 20 72 65 61 | 72 20 70 6f 69 6e 74 65 | the rea|r pointe|
|000014e0| 72 20 69 73 20 6a 75 73 | 74 0d 20 2a 09 4d 41 58 |r is jus|t. *.MAX|
|000014f0| 5f 54 59 50 45 53 2a 28 | 72 70 74 72 20 2d 20 73 |_TYPES*(|rptr - s|
|00001500| 74 61 74 65 29 20 2b 20 | 54 59 50 45 5f 33 20 3d |tate) + |TYPE_3 =|
|00001510| 3d 20 54 59 50 45 5f 33 | 2e 0d 20 2a 2f 0d 0d 73 |= TYPE_3|.. */..s|
|00001520| 74 61 74 69 63 20 20 6c | 6f 6e 67 09 09 72 61 6e |tatic l|ong..ran|
|00001530| 64 74 62 6c 5b 20 44 45 | 47 5f 33 20 2b 20 31 20 |dtbl[ DE|G_3 + 1 |
|00001540| 5d 09 3d 20 7b 20 54 59 | 50 45 5f 33 2c 0d 09 09 |].= { TY|PE_3,...|
|00001550| 09 20 20 20 20 30 78 39 | 61 33 31 39 30 33 39 2c |. 0x9|a319039,|
|00001560| 20 30 78 33 32 64 39 63 | 30 32 34 2c 20 30 78 39 | 0x32d9c|024, 0x9|
|00001570| 62 36 36 33 31 38 32 2c | 20 30 78 35 64 61 31 66 |b663182,| 0x5da1f|
|00001580| 33 34 32 2c 0d 09 09 09 | 20 20 20 20 30 78 64 65 |342,....| 0xde|
|00001590| 33 62 38 31 65 30 2c 20 | 30 78 64 66 30 61 36 66 |3b81e0, |0xdf0a6f|
|000015a0| 62 35 2c 20 30 78 66 31 | 30 33 62 63 30 32 2c 20 |b5, 0xf1|03bc02, |
|000015b0| 30 78 34 38 66 33 34 30 | 66 62 2c 0d 09 09 09 20 |0x48f340|fb,.... |
|000015c0| 20 20 20 30 78 37 34 34 | 39 65 35 36 62 2c 20 30 | 0x744|9e56b, 0|
|000015d0| 78 62 65 62 31 64 62 62 | 30 2c 20 30 78 61 62 35 |xbeb1dbb|0, 0xab5|
|000015e0| 63 35 39 31 38 2c 20 30 | 78 39 34 36 35 35 34 66 |c5918, 0|x946554f|
|000015f0| 64 2c 0d 09 09 09 20 20 | 20 20 30 78 38 63 32 65 |d,.... | 0x8c2e|
|00001600| 36 38 30 66 2c 20 30 78 | 65 62 33 64 37 39 39 66 |680f, 0x|eb3d799f|
|00001610| 2c 20 30 78 62 31 31 65 | 65 30 62 37 2c 20 30 78 |, 0xb11e|e0b7, 0x|
|00001620| 32 64 34 33 36 62 38 36 | 2c 0d 09 09 09 20 20 20 |2d436b86|,.... |
|00001630| 20 30 78 64 61 36 37 32 | 65 32 61 2c 20 30 78 31 | 0xda672|e2a, 0x1|
|00001640| 35 38 38 63 61 38 38 2c | 20 30 78 65 33 36 39 37 |588ca88,| 0xe3697|
|00001650| 33 35 64 2c 20 30 78 39 | 30 34 66 33 35 66 37 2c |35d, 0x9|04f35f7,|
|00001660| 0d 09 09 09 20 20 20 20 | 30 78 64 37 31 35 38 66 |.... |0xd7158f|
|00001670| 64 36 2c 20 30 78 36 66 | 61 36 66 30 35 31 2c 20 |d6, 0x6f|a6f051, |
|00001680| 30 78 36 31 36 65 36 62 | 39 36 2c 20 30 78 61 63 |0x616e6b|96, 0xac|
|00001690| 39 34 65 66 64 63 2c 0d | 09 09 09 20 20 20 20 30 |94efdc,.|... 0|
|000016a0| 78 33 36 34 31 33 66 39 | 33 2c 20 30 78 63 36 32 |x36413f9|3, 0xc62|
|000016b0| 32 63 32 39 38 2c 20 30 | 78 66 35 61 34 32 61 62 |2c298, 0|xf5a42ab|
|000016c0| 38 2c 20 30 78 38 61 38 | 38 64 37 37 62 2c 0d 09 |8, 0x8a8|8d77b,..|
|000016d0| 09 09 09 09 30 78 66 35 | 61 64 39 64 30 65 2c 20 |....0xf5|ad9d0e, |
|000016e0| 30 78 38 39 39 39 32 32 | 30 62 2c 20 30 78 32 37 |0x899922|0b, 0x27|
|000016f0| 66 62 34 37 62 39 20 7d | 3b 0d 0d 2f 2a 0d 20 2a |fb47b9 }|;../*. *|
|00001700| 20 66 70 74 72 20 61 6e | 64 20 72 70 74 72 20 61 | fptr an|d rptr a|
|00001710| 72 65 20 74 77 6f 20 70 | 6f 69 6e 74 65 72 73 20 |re two p|ointers |
|00001720| 69 6e 74 6f 20 74 68 65 | 20 73 74 61 74 65 20 69 |into the| state i|
|00001730| 6e 66 6f 2c 20 61 20 66 | 72 6f 6e 74 20 61 6e 64 |nfo, a f|ront and|
|00001740| 20 61 20 72 65 61 72 0d | 20 2a 20 70 6f 69 6e 74 | a rear.| * point|
|00001750| 65 72 2e 20 20 54 68 65 | 73 65 20 74 77 6f 20 70 |er. The|se two p|
|00001760| 6f 69 6e 74 65 72 73 20 | 61 72 65 20 61 6c 77 61 |ointers |are alwa|
|00001770| 79 73 20 72 61 6e 64 5f | 73 65 70 20 70 6c 61 63 |ys rand_|sep plac|
|00001780| 65 73 20 61 70 61 72 74 | 73 2c 20 61 73 20 74 68 |es apart|s, as th|
|00001790| 65 79 20 63 79 63 6c 65 | 0d 20 2a 20 63 79 63 6c |ey cycle|. * cycl|
|000017a0| 69 63 61 6c 6c 79 20 74 | 68 72 6f 75 67 68 20 74 |ically t|hrough t|
|000017b0| 68 65 20 73 74 61 74 65 | 20 69 6e 66 6f 72 6d 61 |he state| informa|
|000017c0| 74 69 6f 6e 2e 20 20 28 | 59 65 73 2c 20 74 68 69 |tion. (|Yes, thi|
|000017d0| 73 20 64 6f 65 73 20 6d | 65 61 6e 20 77 65 20 63 |s does m|ean we c|
|000017e0| 6f 75 6c 64 20 67 65 74 | 0d 20 2a 20 61 77 61 79 |ould get|. * away|
|000017f0| 20 77 69 74 68 20 6a 75 | 73 74 20 6f 6e 65 20 70 | with ju|st one p|
|00001800| 6f 69 6e 74 65 72 2c 20 | 62 75 74 20 74 68 65 20 |ointer, |but the |
|00001810| 63 6f 64 65 20 66 6f 72 | 20 72 61 6e 64 6f 6d 28 |code for| random(|
|00001820| 29 20 69 73 20 6d 6f 72 | 65 20 65 66 66 69 63 69 |) is mor|e effici|
|00001830| 65 6e 74 20 74 68 69 73 | 0d 20 2a 20 77 61 79 29 |ent this|. * way)|
|00001840| 2e 20 20 54 68 65 20 70 | 6f 69 6e 74 65 72 73 20 |. The p|ointers |
|00001850| 61 72 65 20 6c 65 66 74 | 20 70 6f 73 69 74 69 6f |are left| positio|
|00001860| 6e 65 64 20 61 73 20 74 | 68 65 79 20 77 6f 75 6c |ned as t|hey woul|
|00001870| 64 20 62 65 20 66 72 6f | 6d 20 74 68 65 20 63 61 |d be fro|m the ca|
|00001880| 6c 6c 0d 20 2a 09 09 09 | 69 6e 69 74 73 74 61 74 |ll. *...|initstat|
|00001890| 65 28 20 31 2c 20 72 61 | 6e 64 74 62 6c 2c 20 31 |e( 1, ra|ndtbl, 1|
|000018a0| 32 38 20 29 0d 20 2a 20 | 28 54 68 65 20 70 6f 73 |28 ). * |(The pos|
|000018b0| 69 74 69 6f 6e 20 6f 66 | 20 74 68 65 20 72 65 61 |ition of| the rea|
|000018c0| 72 20 70 6f 69 6e 74 65 | 72 2c 20 72 70 74 72 2c |r pointe|r, rptr,|
|000018d0| 20 69 73 20 72 65 61 6c | 6c 79 20 30 20 28 61 73 | is real|ly 0 (as|
|000018e0| 20 65 78 70 6c 61 69 6e | 65 64 20 61 62 6f 76 65 | explain|ed above|
|000018f0| 0d 20 2a 20 69 6e 20 74 | 68 65 20 69 6e 69 74 69 |. * in t|he initi|
|00001900| 61 6c 69 7a 61 74 69 6f | 6e 20 6f 66 20 72 61 6e |alizatio|n of ran|
|00001910| 64 74 62 6c 29 20 62 65 | 63 61 75 73 65 20 74 68 |dtbl) be|cause th|
|00001920| 65 20 73 74 61 74 65 20 | 74 61 62 6c 65 20 70 6f |e state |table po|
|00001930| 69 6e 74 65 72 20 69 73 | 20 73 65 74 0d 20 2a 20 |inter is| set. * |
|00001940| 74 6f 20 70 6f 69 6e 74 | 20 74 6f 20 72 61 6e 64 |to point| to rand|
|00001950| 74 62 6c 5b 31 5d 20 28 | 61 73 20 65 78 70 6c 61 |tbl[1] (|as expla|
|00001960| 69 6e 65 64 20 62 65 6c | 6f 77 29 2e 0d 20 2a 2f |ined bel|ow).. */|
|00001970| 0d 2f 2a 20 4e 4f 54 45 | 20 73 74 61 74 69 63 73 |./* NOTE| statics|
|00001980| 20 69 6e 76 6f 6c 76 69 | 6e 67 20 61 64 64 72 65 | involvi|ng addre|
|00001990| 73 73 65 73 20 61 72 65 | 20 69 6e 69 74 69 61 6c |sses are| initial|
|000019a0| 69 7a 65 64 20 69 6e 20 | 49 6e 69 74 52 61 6e 64 |ized in |InitRand|
|000019b0| 6f 6d 28 29 20 61 74 0d | 74 68 65 20 62 6f 74 74 |om() at.|the bott|
|000019c0| 6f 6d 20 6f 66 20 74 68 | 69 73 20 66 69 6c 65 2e |om of th|is file.|
|000019d0| 20 2a 2f 0d 0d 73 74 61 | 74 69 63 20 20 6c 6f 6e | */..sta|tic lon|
|000019e0| 67 09 09 2a 66 70 74 72 | 09 09 09 2f 2a 3d 20 26 |g..*fptr|.../*= &|
|000019f0| 72 61 6e 64 74 62 6c 5b | 20 53 45 50 5f 33 20 2b |randtbl[| SEP_3 +|
|00001a00| 20 31 20 5d 2a 2f 3b 0d | 73 74 61 74 69 63 20 20 | 1 ]*/;.|static |
|00001a10| 6c 6f 6e 67 09 09 2a 72 | 70 74 72 09 09 09 2f 2a |long..*r|ptr.../*|
|00001a20| 3d 20 26 72 61 6e 64 74 | 62 6c 5b 20 31 20 5d 2a |= &randt|bl[ 1 ]*|
|00001a30| 2f 3b 0d 0d 0d 0d 2f 2a | 0d 20 2a 20 54 68 65 20 |/;..../*|. * The |
|00001a40| 66 6f 6c 6c 6f 77 69 6e | 67 20 74 68 69 6e 67 73 |followin|g things|
|00001a50| 20 61 72 65 20 74 68 65 | 20 70 6f 69 6e 74 65 72 | are the| pointer|
|00001a60| 20 74 6f 20 74 68 65 20 | 73 74 61 74 65 20 69 6e | to the |state in|
|00001a70| 66 6f 72 6d 61 74 69 6f | 6e 20 74 61 62 6c 65 2c |formatio|n table,|
|00001a80| 0d 20 2a 20 74 68 65 20 | 74 79 70 65 20 6f 66 20 |. * the |type of |
|00001a90| 74 68 65 20 63 75 72 72 | 65 6e 74 20 67 65 6e 65 |the curr|ent gene|
|00001aa0| 72 61 74 6f 72 2c 20 74 | 68 65 20 64 65 67 72 65 |rator, t|he degre|
|00001ab0| 65 20 6f 66 20 74 68 65 | 20 63 75 72 72 65 6e 74 |e of the| current|
|00001ac0| 20 70 6f 6c 79 6e 6f 6d | 69 61 6c 0d 20 2a 20 62 | polynom|ial. * b|
|00001ad0| 65 69 6e 67 20 75 73 65 | 64 2c 20 61 6e 64 20 74 |eing use|d, and t|
|00001ae0| 68 65 20 73 65 70 61 72 | 61 74 69 6f 6e 20 62 65 |he separ|ation be|
|00001af0| 74 77 65 65 6e 20 74 68 | 65 20 74 77 6f 20 70 6f |tween th|e two po|
|00001b00| 69 6e 74 65 72 73 2e 0d | 20 2a 20 4e 6f 74 65 20 |inters..| * Note |
|00001b10| 74 68 61 74 20 66 6f 72 | 20 65 66 66 69 63 69 65 |that for| efficie|
|00001b20| 6e 63 79 20 6f 66 20 72 | 61 6e 64 6f 6d 28 29 2c |ncy of r|andom(),|
|00001b30| 20 77 65 20 72 65 6d 65 | 6d 62 65 72 20 74 68 65 | we reme|mber the|
|00001b40| 20 66 69 72 73 74 20 6c | 6f 63 61 74 69 6f 6e 20 | first l|ocation |
|00001b50| 6f 66 0d 20 2a 20 74 68 | 65 20 73 74 61 74 65 20 |of. * th|e state |
|00001b60| 69 6e 66 6f 72 6d 61 74 | 69 6f 6e 2c 20 6e 6f 74 |informat|ion, not|
|00001b70| 20 74 68 65 20 7a 65 72 | 6f 65 74 68 2e 20 20 48 | the zer|oeth. H|
|00001b80| 65 6e 63 65 20 69 74 20 | 69 73 20 76 61 6c 69 64 |ence it |is valid|
|00001b90| 20 74 6f 20 61 63 63 65 | 73 73 0d 20 2a 20 73 74 | to acce|ss. * st|
|00001ba0| 61 74 65 5b 2d 31 5d 2c | 20 77 68 69 63 68 20 69 |ate[-1],| which i|
|00001bb0| 73 20 75 73 65 64 20 74 | 6f 20 73 74 6f 72 65 20 |s used t|o store |
|00001bc0| 74 68 65 20 74 79 70 65 | 20 6f 66 20 74 68 65 20 |the type| of the |
|00001bd0| 52 2e 4e 2e 47 2e 0d 20 | 2a 20 41 6c 73 6f 2c 20 |R.N.G.. |* Also, |
|00001be0| 77 65 20 72 65 6d 65 6d | 62 65 72 20 74 68 65 20 |we remem|ber the |
|00001bf0| 6c 61 73 74 20 6c 6f 63 | 61 74 69 6f 6e 2c 20 73 |last loc|ation, s|
|00001c00| 69 6e 63 65 20 74 68 69 | 73 20 69 73 20 6d 6f 72 |ince thi|s is mor|
|00001c10| 65 20 65 66 66 69 63 69 | 65 6e 74 20 74 68 61 6e |e effici|ent than|
|00001c20| 0d 20 2a 20 69 6e 64 65 | 78 69 6e 67 20 65 76 65 |. * inde|xing eve|
|00001c30| 72 79 20 74 69 6d 65 20 | 74 6f 20 66 69 6e 64 20 |ry time |to find |
|00001c40| 74 68 65 20 61 64 64 72 | 65 73 73 20 6f 66 20 74 |the addr|ess of t|
|00001c50| 68 65 20 6c 61 73 74 20 | 65 6c 65 6d 65 6e 74 20 |he last |element |
|00001c60| 74 6f 20 73 65 65 20 69 | 66 0d 20 2a 20 74 68 65 |to see i|f. * the|
|00001c70| 20 66 72 6f 6e 74 20 61 | 6e 64 20 72 65 61 72 20 | front a|nd rear |
|00001c80| 70 6f 69 6e 74 65 72 73 | 20 68 61 76 65 20 77 72 |pointers| have wr|
|00001c90| 61 70 70 65 64 2e 0d 20 | 2a 2f 0d 0d 73 74 61 74 |apped.. |*/..stat|
|00001ca0| 69 63 20 20 6c 6f 6e 67 | 09 09 2a 73 74 61 74 65 |ic long|..*state|
|00001cb0| 09 09 09 2f 2a 3d 20 26 | 72 61 6e 64 74 62 6c 5b |.../*= &|randtbl[|
|00001cc0| 20 31 20 5d 2a 2f 3b 0d | 0d 73 74 61 74 69 63 20 | 1 ]*/;.|.static |
|00001cd0| 20 73 68 6f 72 74 09 09 | 72 61 6e 64 5f 74 79 70 | short..|rand_typ|
|00001ce0| 65 09 09 3d 20 54 59 50 | 45 5f 33 3b 0d 73 74 61 |e..= TYP|E_3;.sta|
|00001cf0| 74 69 63 20 20 73 68 6f | 72 74 09 09 72 61 6e 64 |tic sho|rt..rand|
|00001d00| 5f 64 65 67 09 09 3d 20 | 44 45 47 5f 33 3b 0d 73 |_deg..= |DEG_3;.s|
|00001d10| 74 61 74 69 63 20 20 73 | 68 6f 72 74 09 09 72 61 |tatic s|hort..ra|
|00001d20| 6e 64 5f 73 65 70 09 09 | 3d 20 53 45 50 5f 33 3b |nd_sep..|= SEP_3;|
|00001d30| 0d 0d 73 74 61 74 69 63 | 20 20 6c 6f 6e 67 09 09 |..static| long..|
|00001d40| 2a 65 6e 64 5f 70 74 72 | 09 09 2f 2a 3d 20 26 72 |*end_ptr|../*= &r|
|00001d50| 61 6e 64 74 62 6c 5b 20 | 44 45 47 5f 33 20 2b 20 |andtbl[ |DEG_3 + |
|00001d60| 31 20 5d 2a 2f 3b 0d 0d | 0d 0d 2f 2a 0d 20 2a 20 |1 ]*/;..|../*. * |
|00001d70| 73 72 61 6e 64 6f 6d 3a | 0d 20 2a 20 49 6e 69 74 |srandom:|. * Init|
|00001d80| 69 61 6c 69 7a 65 20 74 | 68 65 20 72 61 6e 64 6f |ialize t|he rando|
|00001d90| 6d 20 6e 75 6d 62 65 72 | 20 67 65 6e 65 72 61 74 |m number| generat|
|00001da0| 6f 72 20 62 61 73 65 64 | 20 6f 6e 20 74 68 65 20 |or based| on the |
|00001db0| 67 69 76 65 6e 20 73 65 | 65 64 2e 20 20 49 66 20 |given se|ed. If |
|00001dc0| 74 68 65 0d 20 2a 20 74 | 79 70 65 20 69 73 20 74 |the. * t|ype is t|
|00001dd0| 68 65 20 74 72 69 76 69 | 61 6c 20 6e 6f 2d 73 74 |he trivi|al no-st|
|00001de0| 61 74 65 2d 69 6e 66 6f | 72 6d 61 74 69 6f 6e 20 |ate-info|rmation |
|00001df0| 74 79 70 65 2c 20 6a 75 | 73 74 20 72 65 6d 65 6d |type, ju|st remem|
|00001e00| 62 65 72 20 74 68 65 20 | 73 65 65 64 2e 0d 20 2a |ber the |seed.. *|
|00001e10| 20 4f 74 68 65 72 77 69 | 73 65 2c 20 69 6e 69 74 | Otherwi|se, init|
|00001e20| 69 61 6c 69 7a 65 73 20 | 73 74 61 74 65 5b 5d 20 |ializes |state[] |
|00001e30| 62 61 73 65 64 20 6f 6e | 20 74 68 65 20 67 69 76 |based on| the giv|
|00001e40| 65 6e 20 22 73 65 65 64 | 22 20 76 69 61 20 61 20 |en "seed|" via a |
|00001e50| 6c 69 6e 65 61 72 0d 20 | 2a 20 63 6f 6e 67 72 75 |linear. |* congru|
|00001e60| 65 6e 74 69 61 6c 20 67 | 65 6e 65 72 61 74 6f 72 |ential g|enerator|
|00001e70| 2e 20 20 54 68 65 6e 2c | 20 74 68 65 20 70 6f 69 |. Then,| the poi|
|00001e80| 6e 74 65 72 73 20 61 72 | 65 20 73 65 74 20 74 6f |nters ar|e set to|
|00001e90| 20 6b 6e 6f 77 6e 20 6c | 6f 63 61 74 69 6f 6e 73 | known l|ocations|
|00001ea0| 0d 20 2a 20 74 68 61 74 | 20 61 72 65 20 65 78 61 |. * that| are exa|
|00001eb0| 63 74 6c 79 20 72 61 6e | 64 5f 73 65 70 20 70 6c |ctly ran|d_sep pl|
|00001ec0| 61 63 65 73 20 61 70 61 | 72 74 2e 20 20 4c 61 73 |aces apa|rt. Las|
|00001ed0| 74 6c 79 2c 20 69 74 20 | 63 79 63 6c 65 73 20 74 |tly, it |cycles t|
|00001ee0| 68 65 20 73 74 61 74 65 | 0d 20 2a 20 69 6e 66 6f |he state|. * info|
|00001ef0| 72 6d 61 74 69 6f 6e 20 | 61 20 67 69 76 65 6e 20 |rmation |a given |
|00001f00| 6e 75 6d 62 65 72 20 6f | 66 20 74 69 6d 65 73 20 |number o|f times |
|00001f10| 74 6f 20 67 65 74 20 72 | 69 64 20 6f 66 20 61 6e |to get r|id of an|
|00001f20| 79 20 69 6e 69 74 69 61 | 6c 20 64 65 70 65 6e 64 |y initia|l depend|
|00001f30| 65 6e 63 69 65 73 0d 20 | 2a 20 69 6e 74 72 6f 64 |encies. |* introd|
|00001f40| 75 63 65 64 20 62 79 20 | 74 68 65 20 4c 2e 43 2e |uced by |the L.C.|
|00001f50| 52 2e 4e 2e 47 2e 0d 20 | 2a 20 4e 6f 74 65 20 74 |R.N.G.. |* Note t|
|00001f60| 68 61 74 20 74 68 65 20 | 69 6e 69 74 69 61 6c 69 |hat the |initiali|
|00001f70| 7a 61 74 69 6f 6e 20 6f | 66 20 72 61 6e 64 74 62 |zation o|f randtb|
|00001f80| 6c 5b 5d 20 66 6f 72 20 | 64 65 66 61 75 6c 74 20 |l[] for |default |
|00001f90| 75 73 61 67 65 20 72 65 | 6c 69 65 73 20 6f 6e 0d |usage re|lies on.|
|00001fa0| 20 2a 20 76 61 6c 75 65 | 73 20 70 72 6f 64 75 63 | * value|s produc|
|00001fb0| 65 64 20 62 79 20 74 68 | 69 73 20 72 6f 75 74 69 |ed by th|is routi|
|00001fc0| 6e 65 2e 0d 20 2a 2f 0d | 0d 73 68 6f 72 74 20 73 |ne.. */.|.short s|
|00001fd0| 72 61 6e 64 6f 6d 28 75 | 6e 73 69 67 6e 65 64 20 |random(u|nsigned |
|00001fe0| 78 20 29 0d 7b 0d 20 20 | 20 20 09 72 65 67 69 73 |x ).{. | .regis|
|00001ff0| 74 65 72 20 20 73 68 6f | 72 74 09 09 69 2c 20 6a |ter sho|rt..i, j|
|00002000| 3b 0d 09 6c 6f 6e 67 20 | 72 61 6e 64 6f 6d 28 29 |;..long |random()|
|00002010| 3b 0d 0d 09 69 66 28 20 | 20 72 61 6e 64 5f 74 79 |;...if( | rand_ty|
|00002020| 70 65 20 20 3d 3d 20 20 | 54 59 50 45 5f 30 20 20 |pe == |TYPE_0 |
|00002030| 29 20 20 7b 0d 09 20 20 | 20 20 73 74 61 74 65 5b |) {.. | state[|
|00002040| 20 30 20 5d 20 3d 20 78 | 3b 0d 09 7d 0d 09 65 6c | 0 ] = x|;..}..el|
|00002050| 73 65 20 20 7b 0d 09 20 | 20 20 20 6a 20 3d 20 31 |se {.. | j = 1|
|00002060| 3b 0d 09 20 20 20 20 73 | 74 61 74 65 5b 20 30 20 |;.. s|tate[ 0 |
|00002070| 5d 20 3d 20 78 3b 0d 09 | 20 20 20 20 66 6f 72 28 |] = x;..| for(|
|00002080| 20 69 20 3d 20 31 3b 20 | 69 20 3c 20 72 61 6e 64 | i = 1; |i < rand|
|00002090| 5f 64 65 67 3b 20 69 2b | 2b 20 29 20 20 7b 0d 09 |_deg; i+|+ ) {..|
|000020a0| 09 73 74 61 74 65 5b 69 | 5d 20 3d 20 31 31 30 33 |.state[i|] = 1103|
|000020b0| 35 31 35 32 34 35 2a 73 | 74 61 74 65 5b 69 20 2d |515245*s|tate[i -|
|000020c0| 20 31 5d 20 2b 20 31 32 | 33 34 35 3b 0d 09 20 20 | 1] + 12|345;.. |
|000020d0| 20 20 7d 0d 09 20 20 20 | 20 66 70 74 72 20 3d 20 | }.. | fptr = |
|000020e0| 26 73 74 61 74 65 5b 20 | 72 61 6e 64 5f 73 65 70 |&state[ |rand_sep|
|000020f0| 20 5d 3b 0d 09 20 20 20 | 20 72 70 74 72 20 3d 20 | ];.. | rptr = |
|00002100| 26 73 74 61 74 65 5b 20 | 30 20 5d 3b 0d 09 20 20 |&state[ |0 ];.. |
|00002110| 20 20 66 6f 72 28 20 69 | 20 3d 20 30 3b 20 69 20 | for( i| = 0; i |
|00002120| 3c 20 31 30 2a 72 61 6e | 64 5f 64 65 67 3b 20 69 |< 10*ran|d_deg; i|
|00002130| 2b 2b 20 29 20 20 72 61 | 6e 64 6f 6d 28 29 3b 0d |++ ) ra|ndom();.|
|00002140| 09 7d 0d 7d 0d 0d 0d 0d | 2f 2a 0d 20 2a 20 69 6e |.}.}....|/*. * in|
|00002150| 69 74 73 74 61 74 65 3a | 0d 20 2a 20 49 6e 69 74 |itstate:|. * Init|
|00002160| 69 61 6c 69 7a 65 20 74 | 68 65 20 73 74 61 74 65 |ialize t|he state|
|00002170| 20 69 6e 66 6f 72 6d 61 | 74 69 6f 6e 20 69 6e 20 | informa|tion in |
|00002180| 74 68 65 20 67 69 76 65 | 6e 20 61 72 72 61 79 20 |the give|n array |
|00002190| 6f 66 20 6e 20 62 79 74 | 65 73 20 66 6f 72 0d 20 |of n byt|es for. |
|000021a0| 2a 20 66 75 74 75 72 65 | 20 72 61 6e 64 6f 6d 20 |* future| random |
|000021b0| 6e 75 6d 62 65 72 20 67 | 65 6e 65 72 61 74 69 6f |number g|eneratio|
|000021c0| 6e 2e 20 20 42 61 73 65 | 64 20 6f 6e 20 74 68 65 |n. Base|d on the|
|000021d0| 20 6e 75 6d 62 65 72 20 | 6f 66 20 62 79 74 65 73 | number |of bytes|
|000021e0| 20 77 65 0d 20 2a 20 61 | 72 65 20 67 69 76 65 6e | we. * a|re given|
|000021f0| 2c 20 61 6e 64 20 74 68 | 65 20 62 72 65 61 6b 20 |, and th|e break |
|00002200| 76 61 6c 75 65 73 20 66 | 6f 72 20 74 68 65 20 64 |values f|or the d|
|00002210| 69 66 66 65 72 65 6e 74 | 20 52 2e 4e 2e 47 2e 27 |ifferent| R.N.G.'|
|00002220| 73 2c 20 77 65 20 63 68 | 6f 6f 73 65 0d 20 2a 20 |s, we ch|oose. * |
|00002230| 74 68 65 20 62 65 73 74 | 20 28 6c 61 72 67 65 73 |the best| (larges|
|00002240| 74 29 20 6f 6e 65 20 77 | 65 20 63 61 6e 20 61 6e |t) one w|e can an|
|00002250| 64 20 73 65 74 20 74 68 | 69 6e 67 73 20 75 70 20 |d set th|ings up |
|00002260| 66 6f 72 20 69 74 2e 20 | 20 73 72 61 6e 64 6f 6d |for it. | srandom|
|00002270| 28 29 20 69 73 0d 20 2a | 20 74 68 65 6e 20 63 61 |() is. *| then ca|
|00002280| 6c 6c 65 64 20 74 6f 20 | 69 6e 69 74 69 61 6c 69 |lled to |initiali|
|00002290| 7a 65 20 74 68 65 20 73 | 74 61 74 65 20 69 6e 66 |ze the s|tate inf|
|000022a0| 6f 72 6d 61 74 69 6f 6e | 2e 0d 20 2a 20 4e 6f 74 |ormation|.. * Not|
|000022b0| 65 20 74 68 61 74 20 6f | 6e 20 72 65 74 75 72 6e |e that o|n return|
|000022c0| 20 66 72 6f 6d 20 73 72 | 61 6e 64 6f 6d 28 29 2c | from sr|andom(),|
|000022d0| 20 77 65 20 73 65 74 20 | 73 74 61 74 65 5b 2d 31 | we set |state[-1|
|000022e0| 5d 20 74 6f 20 62 65 20 | 74 68 65 20 74 79 70 65 |] to be |the type|
|000022f0| 0d 20 2a 20 6d 75 6c 74 | 69 70 6c 65 78 65 64 20 |. * mult|iplexed |
|00002300| 77 69 74 68 20 74 68 65 | 20 63 75 72 72 65 6e 74 |with the| current|
|00002310| 20 76 61 6c 75 65 20 6f | 66 20 74 68 65 20 72 65 | value o|f the re|
|00002320| 61 72 20 70 6f 69 6e 74 | 65 72 3b 20 74 68 69 73 |ar point|er; this|
|00002330| 20 69 73 20 73 6f 0d 20 | 2a 20 73 75 63 63 65 73 | is so. |* succes|
|00002340| 73 69 76 65 20 63 61 6c | 6c 73 20 74 6f 20 69 6e |sive cal|ls to in|
|00002350| 69 74 73 74 61 74 65 28 | 29 20 77 6f 6e 27 74 20 |itstate(|) won't |
|00002360| 6c 6f 73 65 20 74 68 69 | 73 20 69 6e 66 6f 72 6d |lose thi|s inform|
|00002370| 61 74 69 6f 6e 20 61 6e | 64 20 77 69 6c 6c 0d 20 |ation an|d will. |
|00002380| 2a 20 62 65 20 61 62 6c | 65 20 74 6f 20 72 65 73 |* be abl|e to res|
|00002390| 74 61 72 74 20 77 69 74 | 68 20 73 65 74 73 74 61 |tart wit|h setsta|
|000023a0| 74 65 28 29 2e 0d 20 2a | 20 4e 6f 74 65 3a 20 74 |te().. *| Note: t|
|000023b0| 68 65 20 66 69 72 73 74 | 20 74 68 69 6e 67 20 77 |he first| thing w|
|000023c0| 65 20 64 6f 20 69 73 20 | 73 61 76 65 20 74 68 65 |e do is |save the|
|000023d0| 20 63 75 72 72 65 6e 74 | 20 73 74 61 74 65 2c 20 | current| state, |
|000023e0| 69 66 20 61 6e 79 2c 20 | 6a 75 73 74 20 6c 69 6b |if any, |just lik|
|000023f0| 65 0d 20 2a 20 73 65 74 | 73 74 61 74 65 28 29 20 |e. * set|state() |
|00002400| 73 6f 20 74 68 61 74 20 | 69 74 20 64 6f 65 73 6e |so that |it doesn|
|00002410| 27 74 20 6d 61 74 74 65 | 72 20 77 68 65 6e 20 69 |'t matte|r when i|
|00002420| 6e 69 74 73 74 61 74 65 | 20 69 73 20 63 61 6c 6c |nitstate| is call|
|00002430| 65 64 2e 0d 20 2a 20 52 | 65 74 75 72 6e 73 20 61 |ed.. * R|eturns a|
|00002440| 20 70 6f 69 6e 74 65 72 | 20 74 6f 20 74 68 65 20 | pointer| to the |
|00002450| 6f 6c 64 20 73 74 61 74 | 65 2e 0d 20 2a 2f 0d 0d |old stat|e.. */..|
|00002460| 63 68 61 72 20 20 2a 69 | 6e 69 74 73 74 61 74 65 |char *i|nitstate|
|00002470| 28 75 6e 73 69 67 6e 65 | 64 20 73 65 65 64 2c 20 |(unsigne|d seed, |
|00002480| 63 68 61 72 20 2a 61 72 | 67 5f 73 74 61 74 65 2c |char *ar|g_state,|
|00002490| 20 73 68 6f 72 74 20 6e | 20 29 0d 20 20 2f 2a 20 | short n| ). /* |
|000024a0| 20 75 6e 73 69 67 6e 65 | 64 09 09 73 65 65 64 3b | unsigne|d..seed;|
|000024b0| 09 09 09 20 73 65 65 64 | 20 66 6f 72 20 52 2e 20 |... seed| for R. |
|000024c0| 4e 2e 20 47 2e 20 2a 2f | 0d 20 20 2f 2a 20 20 63 |N. G. */|. /* c|
|000024d0| 68 61 72 09 09 2a 61 72 | 67 5f 73 74 61 74 65 3b |har..*ar|g_state;|
|000024e0| 09 09 20 70 6f 69 6e 74 | 65 72 20 74 6f 20 73 74 |.. point|er to st|
|000024f0| 61 74 65 20 61 72 72 61 | 79 20 2a 2f 0d 20 20 2f |ate arra|y */. /|
|00002500| 2a 20 73 68 6f 72 74 09 | 09 09 6e 3b 09 09 09 20 |* short.|..n;... |
|00002510| 23 20 62 79 74 65 73 20 | 6f 66 20 73 74 61 74 65 |# bytes |of state|
|00002520| 20 69 6e 66 6f 20 2a 2f | 0d 7b 0d 09 72 65 67 69 | info */|.{..regi|
|00002530| 73 74 65 72 20 20 63 68 | 61 72 09 09 2a 6f 73 74 |ster ch|ar..*ost|
|00002540| 61 74 65 09 09 3d 20 28 | 63 68 61 72 20 2a 29 28 |ate..= (|char *)(|
|00002550| 20 26 73 74 61 74 65 5b | 20 2d 31 20 5d 20 29 3b | &state[| -1 ] );|
|00002560| 0d 0d 09 69 66 28 20 20 | 72 61 6e 64 5f 74 79 70 |...if( |rand_typ|
|00002570| 65 20 20 3d 3d 20 20 54 | 59 50 45 5f 30 20 20 29 |e == T|YPE_0 )|
|00002580| 20 20 73 74 61 74 65 5b | 20 2d 31 20 5d 20 3d 20 | state[| -1 ] = |
|00002590| 72 61 6e 64 5f 74 79 70 | 65 3b 0d 09 65 6c 73 65 |rand_typ|e;..else|
|000025a0| 20 20 73 74 61 74 65 5b | 20 2d 31 20 5d 20 3d 20 | state[| -1 ] = |
|000025b0| 4d 41 58 5f 54 59 50 45 | 53 2a 28 72 70 74 72 20 |MAX_TYPE|S*(rptr |
|000025c0| 2d 20 73 74 61 74 65 29 | 20 2b 20 72 61 6e 64 5f |- state)| + rand_|
|000025d0| 74 79 70 65 3b 0d 09 69 | 66 28 20 20 6e 20 20 3c |type;..i|f( n <|
|000025e0| 20 20 42 52 45 41 4b 5f | 31 20 20 29 20 20 7b 0d | BREAK_|1 ) {.|
|000025f0| 09 20 20 20 20 69 66 28 | 20 20 6e 20 20 3c 20 20 |. if(| n < |
|00002600| 42 52 45 41 4b 5f 30 20 | 20 29 20 20 7b 0d 09 09 |BREAK_0 | ) {...|
|00002610| 66 70 72 69 6e 74 66 28 | 20 73 74 64 65 72 72 2c |fprintf(| stderr,|
|00002620| 20 22 69 6e 69 74 73 74 | 61 74 65 3a 20 6e 6f 74 | "initst|ate: not|
|00002630| 20 65 6e 6f 75 67 68 20 | 73 74 61 74 65 20 28 25 | enough |state (%|
|00002640| 64 20 62 79 74 65 73 29 | 20 77 69 74 68 20 77 68 |d bytes)| with wh|
|00002650| 69 63 68 20 74 6f 20 64 | 6f 20 6a 61 63 6b 3b 20 |ich to d|o jack; |
|00002660| 69 67 6e 6f 72 65 64 2e | 5c 6e 22 2c 20 6e 20 29 |ignored.|\n", n )|
|00002670| 3b 0d 09 09 72 65 74 75 | 72 6e 20 30 3b 0d 09 20 |;...retu|rn 0;.. |
|00002680| 20 20 20 7d 0d 09 20 20 | 20 20 72 61 6e 64 5f 74 | }.. | rand_t|
|00002690| 79 70 65 20 3d 20 54 59 | 50 45 5f 30 3b 0d 09 20 |ype = TY|PE_0;.. |
|000026a0| 20 20 20 72 61 6e 64 5f | 64 65 67 20 3d 20 44 45 | rand_|deg = DE|
|000026b0| 47 5f 30 3b 0d 09 20 20 | 20 20 72 61 6e 64 5f 73 |G_0;.. | rand_s|
|000026c0| 65 70 20 3d 20 53 45 50 | 5f 30 3b 0d 09 7d 0d 09 |ep = SEP|_0;..}..|
|000026d0| 65 6c 73 65 20 20 7b 0d | 09 20 20 20 20 69 66 28 |else {.|. if(|
|000026e0| 20 20 6e 20 20 3c 20 20 | 42 52 45 41 4b 5f 32 20 | n < |BREAK_2 |
|000026f0| 20 29 20 20 7b 0d 09 09 | 72 61 6e 64 5f 74 79 70 | ) {...|rand_typ|
|00002700| 65 20 3d 20 54 59 50 45 | 5f 31 3b 0d 09 09 72 61 |e = TYPE|_1;...ra|
|00002710| 6e 64 5f 64 65 67 20 3d | 20 44 45 47 5f 31 3b 0d |nd_deg =| DEG_1;.|
|00002720| 09 09 72 61 6e 64 5f 73 | 65 70 20 3d 20 53 45 50 |..rand_s|ep = SEP|
|00002730| 5f 31 3b 0d 09 20 20 20 | 20 7d 0d 09 20 20 20 20 |_1;.. | }.. |
|00002740| 65 6c 73 65 20 20 7b 0d | 09 09 69 66 28 20 20 6e |else {.|..if( n|
|00002750| 20 20 3c 20 20 42 52 45 | 41 4b 5f 33 20 20 29 20 | < BRE|AK_3 ) |
|00002760| 20 7b 0d 09 09 20 20 20 | 20 72 61 6e 64 5f 74 79 | {... | rand_ty|
|00002770| 70 65 20 3d 20 54 59 50 | 45 5f 32 3b 0d 09 09 20 |pe = TYP|E_2;... |
|00002780| 20 20 20 72 61 6e 64 5f | 64 65 67 20 3d 20 44 45 | rand_|deg = DE|
|00002790| 47 5f 32 3b 0d 09 09 20 | 20 20 20 72 61 6e 64 5f |G_2;... | rand_|
|000027a0| 73 65 70 20 3d 20 53 45 | 50 5f 32 3b 0d 09 09 7d |sep = SE|P_2;...}|
|000027b0| 0d 09 09 65 6c 73 65 20 | 20 7b 0d 09 09 20 20 20 |...else | {... |
|000027c0| 20 69 66 28 20 20 6e 20 | 20 3c 20 20 42 52 45 41 | if( n | < BREA|
|000027d0| 4b 5f 34 20 20 29 20 20 | 7b 0d 09 09 09 72 61 6e |K_4 ) |{....ran|
|000027e0| 64 5f 74 79 70 65 20 3d | 20 54 59 50 45 5f 33 3b |d_type =| TYPE_3;|
|000027f0| 0d 09 09 09 72 61 6e 64 | 5f 64 65 67 20 3d 20 44 |....rand|_deg = D|
|00002800| 45 47 5f 33 3b 0d 09 09 | 09 72 61 6e 64 5f 73 65 |EG_3;...|.rand_se|
|00002810| 70 20 3d 20 53 45 50 5f | 33 3b 0d 09 09 20 20 20 |p = SEP_|3;... |
|00002820| 20 7d 0d 09 09 20 20 20 | 20 65 6c 73 65 20 20 7b | }... | else {|
|00002830| 0d 09 09 09 72 61 6e 64 | 5f 74 79 70 65 20 3d 20 |....rand|_type = |
|00002840| 54 59 50 45 5f 34 3b 0d | 09 09 09 72 61 6e 64 5f |TYPE_4;.|...rand_|
|00002850| 64 65 67 20 3d 20 44 45 | 47 5f 34 3b 0d 09 09 09 |deg = DE|G_4;....|
|00002860| 72 61 6e 64 5f 73 65 70 | 20 3d 20 53 45 50 5f 34 |rand_sep| = SEP_4|
|00002870| 3b 0d 09 09 20 20 20 20 | 7d 0d 09 09 7d 0d 09 20 |;... |}...}.. |
|00002880| 20 20 20 7d 0d 09 7d 0d | 09 73 74 61 74 65 20 3d | }..}.|.state =|
|00002890| 20 26 28 20 20 28 20 28 | 6c 6f 6e 67 20 2a 29 61 | &( ( (|long *)a|
|000028a0| 72 67 5f 73 74 61 74 65 | 20 29 5b 31 5d 20 20 29 |rg_state| )[1] )|
|000028b0| 3b 09 2f 2a 20 66 69 72 | 73 74 20 6c 6f 63 61 74 |;./* fir|st locat|
|000028c0| 69 6f 6e 20 2a 2f 0d 09 | 65 6e 64 5f 70 74 72 20 |ion */..|end_ptr |
|000028d0| 3d 20 26 73 74 61 74 65 | 5b 20 72 61 6e 64 5f 64 |= &state|[ rand_d|
|000028e0| 65 67 20 5d 3b 09 2f 2a | 20 6d 75 73 74 20 73 65 |eg ];./*| must se|
|000028f0| 74 20 65 6e 64 5f 70 74 | 72 20 62 65 66 6f 72 65 |t end_pt|r before|
|00002900| 20 73 72 61 6e 64 6f 6d | 20 2a 2f 0d 09 73 72 61 | srandom| */..sra|
|00002910| 6e 64 6f 6d 28 20 73 65 | 65 64 20 29 3b 0d 09 69 |ndom( se|ed );..i|
|00002920| 66 28 20 20 72 61 6e 64 | 5f 74 79 70 65 20 20 3d |f( rand|_type =|
|00002930| 3d 20 20 54 59 50 45 5f | 30 20 20 29 20 20 73 74 |= TYPE_|0 ) st|
|00002940| 61 74 65 5b 20 2d 31 20 | 5d 20 3d 20 72 61 6e 64 |ate[ -1 |] = rand|
|00002950| 5f 74 79 70 65 3b 0d 09 | 65 6c 73 65 20 20 73 74 |_type;..|else st|
|00002960| 61 74 65 5b 20 2d 31 20 | 5d 20 3d 20 4d 41 58 5f |ate[ -1 |] = MAX_|
|00002970| 54 59 50 45 53 2a 28 72 | 70 74 72 20 2d 20 73 74 |TYPES*(r|ptr - st|
|00002980| 61 74 65 29 20 2b 20 72 | 61 6e 64 5f 74 79 70 65 |ate) + r|and_type|
|00002990| 3b 0d 09 72 65 74 75 72 | 6e 28 20 6f 73 74 61 74 |;..retur|n( ostat|
|000029a0| 65 20 29 3b 0d 7d 0d 0d | 0d 0d 2f 2a 0d 20 2a 20 |e );.}..|../*. * |
|000029b0| 73 65 74 73 74 61 74 65 | 3a 0d 20 2a 20 52 65 73 |setstate|:. * Res|
|000029c0| 74 6f 72 65 20 74 68 65 | 20 73 74 61 74 65 20 66 |tore the| state f|
|000029d0| 72 6f 6d 20 74 68 65 20 | 67 69 76 65 6e 20 73 74 |rom the |given st|
|000029e0| 61 74 65 20 61 72 72 61 | 79 2e 0d 20 2a 20 4e 6f |ate arra|y.. * No|
|000029f0| 74 65 3a 20 69 74 20 69 | 73 20 69 6d 70 6f 72 74 |te: it i|s import|
|00002a00| 61 6e 74 20 74 68 61 74 | 20 77 65 20 61 6c 73 6f |ant that| we also|
|00002a10| 20 72 65 6d 65 6d 62 65 | 72 20 74 68 65 20 6c 6f | remembe|r the lo|
|00002a20| 63 61 74 69 6f 6e 73 20 | 6f 66 20 74 68 65 20 70 |cations |of the p|
|00002a30| 6f 69 6e 74 65 72 73 0d | 20 2a 20 69 6e 20 74 68 |ointers.| * in th|
|00002a40| 65 20 63 75 72 72 65 6e | 74 20 73 74 61 74 65 20 |e curren|t state |
|00002a50| 69 6e 66 6f 72 6d 61 74 | 69 6f 6e 2c 20 61 6e 64 |informat|ion, and|
|00002a60| 20 72 65 73 74 6f 72 65 | 20 74 68 65 20 6c 6f 63 | restore| the loc|
|00002a70| 61 74 69 6f 6e 73 20 6f | 66 20 74 68 65 20 70 6f |ations o|f the po|
|00002a80| 69 6e 74 65 72 73 0d 20 | 2a 20 66 72 6f 6d 20 74 |inters. |* from t|
|00002a90| 68 65 20 6f 6c 64 20 73 | 74 61 74 65 20 69 6e 66 |he old s|tate inf|
|00002aa0| 6f 72 6d 61 74 69 6f 6e | 2e 20 20 54 68 69 73 20 |ormation|. This |
|00002ab0| 69 73 20 64 6f 6e 65 20 | 62 79 20 6d 75 6c 74 69 |is done |by multi|
|00002ac0| 70 6c 65 78 69 6e 67 20 | 74 68 65 20 70 6f 69 6e |plexing |the poin|
|00002ad0| 74 65 72 0d 20 2a 20 6c | 6f 63 61 74 69 6f 6e 20 |ter. * l|ocation |
|00002ae0| 69 6e 74 6f 20 74 68 65 | 20 7a 65 72 6f 65 74 68 |into the| zeroeth|
|00002af0| 20 77 6f 72 64 20 6f 66 | 20 74 68 65 20 73 74 61 | word of| the sta|
|00002b00| 74 65 20 69 6e 66 6f 72 | 6d 61 74 69 6f 6e 2e 0d |te infor|mation..|
|00002b10| 20 2a 20 4e 6f 74 65 20 | 74 68 61 74 20 64 75 65 | * Note |that due|
|00002b20| 20 74 6f 20 74 68 65 20 | 6f 72 64 65 72 20 69 6e | to the |order in|
|00002b30| 20 77 68 69 63 68 20 74 | 68 69 6e 67 73 20 61 72 | which t|hings ar|
|00002b40| 65 20 64 6f 6e 65 2c 20 | 69 74 20 69 73 20 4f 4b |e done, |it is OK|
|00002b50| 20 74 6f 20 63 61 6c 6c | 0d 20 2a 20 73 65 74 73 | to call|. * sets|
|00002b60| 74 61 74 65 28 29 20 77 | 69 74 68 20 74 68 65 20 |tate() w|ith the |
|00002b70| 73 61 6d 65 20 73 74 61 | 74 65 20 61 73 20 74 68 |same sta|te as th|
|00002b80| 65 20 63 75 72 72 65 6e | 74 20 73 74 61 74 65 2e |e curren|t state.|
|00002b90| 0d 20 2a 20 52 65 74 75 | 72 6e 73 20 61 20 70 6f |. * Retu|rns a po|
|00002ba0| 69 6e 74 65 72 20 74 6f | 20 74 68 65 20 6f 6c 64 |inter to| the old|
|00002bb0| 20 73 74 61 74 65 20 69 | 6e 66 6f 72 6d 61 74 69 | state i|nformati|
|00002bc0| 6f 6e 2e 0d 20 2a 2f 0d | 0d 63 68 61 72 20 20 2a |on.. */.|.char *|
|00002bd0| 73 65 74 73 74 61 74 65 | 28 63 68 61 72 20 2a 61 |setstate|(char *a|
|00002be0| 72 67 5f 73 74 61 74 65 | 20 29 0d 7b 0d 09 72 65 |rg_state| ).{..re|
|00002bf0| 67 69 73 74 65 72 20 20 | 6c 6f 6e 67 09 09 2a 6e |gister |long..*n|
|00002c00| 65 77 5f 73 74 61 74 65 | 09 3d 20 28 6c 6f 6e 67 |ew_state|.= (long|
|00002c10| 20 2a 29 61 72 67 5f 73 | 74 61 74 65 3b 0d 09 72 | *)arg_s|tate;..r|
|00002c20| 65 67 69 73 74 65 72 20 | 20 73 68 6f 72 74 09 09 |egister | short..|
|00002c30| 74 79 70 65 09 09 3d 20 | 6e 65 77 5f 73 74 61 74 |type..= |new_stat|
|00002c40| 65 5b 30 5d 25 4d 41 58 | 5f 54 59 50 45 53 3b 0d |e[0]%MAX|_TYPES;.|
|00002c50| 09 72 65 67 69 73 74 65 | 72 20 20 73 68 6f 72 74 |.registe|r short|
|00002c60| 09 09 72 65 61 72 09 09 | 3d 20 6e 65 77 5f 73 74 |..rear..|= new_st|
|00002c70| 61 74 65 5b 30 5d 2f 4d | 41 58 5f 54 59 50 45 53 |ate[0]/M|AX_TYPES|
|00002c80| 3b 0d 09 63 68 61 72 09 | 09 09 2a 6f 73 74 61 74 |;..char.|..*ostat|
|00002c90| 65 09 09 3d 20 28 63 68 | 61 72 20 2a 29 28 20 26 |e..= (ch|ar *)( &|
|00002ca0| 73 74 61 74 65 5b 20 2d | 31 20 5d 20 29 3b 0d 0d |state[ -|1 ] );..|
|00002cb0| 09 69 66 28 20 20 72 61 | 6e 64 5f 74 79 70 65 20 |.if( ra|nd_type |
|00002cc0| 20 3d 3d 20 20 54 59 50 | 45 5f 30 20 20 29 20 20 | == TYP|E_0 ) |
|00002cd0| 73 74 61 74 65 5b 20 2d | 31 20 5d 20 3d 20 72 61 |state[ -|1 ] = ra|
|00002ce0| 6e 64 5f 74 79 70 65 3b | 0d 09 65 6c 73 65 20 20 |nd_type;|..else |
|00002cf0| 73 74 61 74 65 5b 20 2d | 31 20 5d 20 3d 20 4d 41 |state[ -|1 ] = MA|
|00002d00| 58 5f 54 59 50 45 53 2a | 28 72 70 74 72 20 2d 20 |X_TYPES*|(rptr - |
|00002d10| 73 74 61 74 65 29 20 2b | 20 72 61 6e 64 5f 74 79 |state) +| rand_ty|
|00002d20| 70 65 3b 0d 09 73 77 69 | 74 63 68 28 20 20 74 79 |pe;..swi|tch( ty|
|00002d30| 70 65 20 20 29 20 20 7b | 0d 09 20 20 20 20 63 61 |pe ) {|.. ca|
|00002d40| 73 65 20 20 54 59 50 45 | 5f 30 3a 0d 09 20 20 20 |se TYPE|_0:.. |
|00002d50| 20 63 61 73 65 20 20 54 | 59 50 45 5f 31 3a 0d 09 | case T|YPE_1:..|
|00002d60| 20 20 20 20 63 61 73 65 | 20 20 54 59 50 45 5f 32 | case| TYPE_2|
|00002d70| 3a 0d 09 20 20 20 20 63 | 61 73 65 20 20 54 59 50 |:.. c|ase TYP|
|00002d80| 45 5f 33 3a 0d 09 20 20 | 20 20 63 61 73 65 20 20 |E_3:.. | case |
|00002d90| 54 59 50 45 5f 34 3a 0d | 09 09 72 61 6e 64 5f 74 |TYPE_4:.|..rand_t|
|00002da0| 79 70 65 20 3d 20 74 79 | 70 65 3b 0d 09 09 72 61 |ype = ty|pe;...ra|
|00002db0| 6e 64 5f 64 65 67 20 3d | 20 64 65 67 72 65 65 73 |nd_deg =| degrees|
|00002dc0| 5b 20 74 79 70 65 20 5d | 3b 0d 09 09 72 61 6e 64 |[ type ]|;...rand|
|00002dd0| 5f 73 65 70 20 3d 20 73 | 65 70 73 5b 20 74 79 70 |_sep = s|eps[ typ|
|00002de0| 65 20 5d 3b 0d 09 09 62 | 72 65 61 6b 3b 0d 0d 09 |e ];...b|reak;...|
|00002df0| 20 20 20 20 64 65 66 61 | 75 6c 74 3a 0d 09 09 66 | defa|ult:...f|
|00002e00| 70 72 69 6e 74 66 28 20 | 73 74 64 65 72 72 2c 20 |printf( |stderr, |
|00002e10| 22 73 65 74 73 74 61 74 | 65 3a 20 73 74 61 74 65 |"setstat|e: state|
|00002e20| 20 69 6e 66 6f 20 68 61 | 73 20 62 65 65 6e 20 6d | info ha|s been m|
|00002e30| 75 6e 67 65 64 3b 20 6e | 6f 74 20 63 68 61 6e 67 |unged; n|ot chang|
|00002e40| 65 64 2e 5c 6e 22 20 29 | 3b 0d 09 7d 0d 09 73 74 |ed.\n" )|;..}..st|
|00002e50| 61 74 65 20 3d 20 26 6e | 65 77 5f 73 74 61 74 65 |ate = &n|ew_state|
|00002e60| 5b 20 31 20 5d 3b 0d 09 | 69 66 28 20 20 72 61 6e |[ 1 ];..|if( ran|
|00002e70| 64 5f 74 79 70 65 20 20 | 21 3d 20 20 54 59 50 45 |d_type |!= TYPE|
|00002e80| 5f 30 20 20 29 20 20 7b | 0d 09 20 20 20 20 72 70 |_0 ) {|.. rp|
|00002e90| 74 72 20 3d 20 26 73 74 | 61 74 65 5b 20 72 65 61 |tr = &st|ate[ rea|
|00002ea0| 72 20 5d 3b 0d 09 20 20 | 20 20 66 70 74 72 20 3d |r ];.. | fptr =|
|00002eb0| 20 26 73 74 61 74 65 5b | 20 28 72 65 61 72 20 2b | &state[| (rear +|
|00002ec0| 20 72 61 6e 64 5f 73 65 | 70 29 25 72 61 6e 64 5f | rand_se|p)%rand_|
|00002ed0| 64 65 67 20 5d 3b 0d 09 | 7d 0d 09 65 6e 64 5f 70 |deg ];..|}..end_p|
|00002ee0| 74 72 20 3d 20 26 73 74 | 61 74 65 5b 20 72 61 6e |tr = &st|ate[ ran|
|00002ef0| 64 5f 64 65 67 20 5d 3b | 09 09 2f 2a 20 73 65 74 |d_deg ];|../* set|
|00002f00| 20 65 6e 64 5f 70 74 72 | 20 74 6f 6f 20 2a 2f 0d | end_ptr| too */.|
|00002f10| 09 72 65 74 75 72 6e 28 | 20 6f 73 74 61 74 65 20 |.return(| ostate |
|00002f20| 29 3b 0d 7d 0d 0d 0d 0d | 2f 2a 0d 20 2a 20 72 61 |);.}....|/*. * ra|
|00002f30| 6e 64 6f 6d 3a 0d 20 2a | 20 49 66 20 77 65 20 61 |ndom:. *| If we a|
|00002f40| 72 65 20 75 73 69 6e 67 | 20 74 68 65 20 74 72 69 |re using| the tri|
|00002f50| 76 69 61 6c 20 54 59 50 | 45 5f 30 20 52 2e 4e 2e |vial TYP|E_0 R.N.|
|00002f60| 47 2e 2c 20 6a 75 73 74 | 20 64 6f 20 74 68 65 20 |G., just| do the |
|00002f70| 6f 6c 64 20 6c 69 6e 65 | 61 72 0d 20 2a 20 63 6f |old line|ar. * co|
|00002f80| 6e 67 72 75 65 6e 74 69 | 61 6c 20 62 69 74 2e 20 |ngruenti|al bit. |
|00002f90| 20 4f 74 68 65 72 77 69 | 73 65 2c 20 77 65 20 64 | Otherwi|se, we d|
|00002fa0| 6f 20 6f 75 72 20 66 61 | 6e 63 79 20 74 72 69 6e |o our fa|ncy trin|
|00002fb0| 6f 6d 69 61 6c 20 73 74 | 75 66 66 2c 20 77 68 69 |omial st|uff, whi|
|00002fc0| 63 68 20 69 73 20 74 68 | 65 0d 20 2a 20 73 61 6d |ch is th|e. * sam|
|00002fd0| 65 20 69 6e 20 61 6c 6c | 20 74 68 65 72 20 6f 74 |e in all| ther ot|
|00002fe0| 68 65 72 20 63 61 73 65 | 73 20 64 75 65 20 74 6f |her case|s due to|
|00002ff0| 20 61 6c 6c 20 74 68 65 | 20 67 6c 6f 62 61 6c 20 | all the| global |
|00003000| 76 61 72 69 61 62 6c 65 | 73 20 74 68 61 74 20 68 |variable|s that h|
|00003010| 61 76 65 20 62 65 65 6e | 0d 20 2a 20 73 65 74 20 |ave been|. * set |
|00003020| 75 70 2e 20 20 54 68 65 | 20 62 61 73 69 63 20 6f |up. The| basic o|
|00003030| 70 65 72 61 74 69 6f 6e | 20 69 73 20 74 6f 20 61 |peration| is to a|
|00003040| 64 64 20 74 68 65 20 6e | 75 6d 62 65 72 20 61 74 |dd the n|umber at|
|00003050| 20 74 68 65 20 72 65 61 | 72 20 70 6f 69 6e 74 65 | the rea|r pointe|
|00003060| 72 20 69 6e 74 6f 0d 20 | 2a 20 74 68 65 20 6f 6e |r into. |* the on|
|00003070| 65 20 61 74 20 74 68 65 | 20 66 72 6f 6e 74 20 70 |e at the| front p|
|00003080| 6f 69 6e 74 65 72 2e 20 | 20 54 68 65 6e 20 62 6f |ointer. | Then bo|
|00003090| 74 68 20 70 6f 69 6e 74 | 65 72 73 20 61 72 65 20 |th point|ers are |
|000030a0| 61 64 76 61 6e 63 65 64 | 20 74 6f 20 74 68 65 20 |advanced| to the |
|000030b0| 6e 65 78 74 0d 20 2a 20 | 6c 6f 63 61 74 69 6f 6e |next. * |location|
|000030c0| 20 63 79 63 6c 69 63 61 | 6c 6c 79 20 69 6e 20 74 | cyclica|lly in t|
|000030d0| 68 65 20 74 61 62 6c 65 | 2e 20 20 54 68 65 20 76 |he table|. The v|
|000030e0| 61 6c 75 65 20 72 65 74 | 75 72 6e 65 64 20 69 73 |alue ret|urned is|
|000030f0| 20 74 68 65 20 73 75 6d | 20 67 65 6e 65 72 61 74 | the sum| generat|
|00003100| 65 64 2c 0d 20 2a 20 72 | 65 64 75 63 65 64 20 74 |ed,. * r|educed t|
|00003110| 6f 20 33 31 20 62 69 74 | 73 20 62 79 20 74 68 72 |o 31 bit|s by thr|
|00003120| 6f 77 69 6e 67 20 61 77 | 61 79 20 74 68 65 20 22 |owing aw|ay the "|
|00003130| 6c 65 61 73 74 20 72 61 | 6e 64 6f 6d 22 20 6c 6f |least ra|ndom" lo|
|00003140| 77 20 62 69 74 2e 0d 20 | 2a 20 4e 6f 74 65 3a 20 |w bit.. |* Note: |
|00003150| 74 68 65 20 63 6f 64 65 | 20 74 61 6b 65 73 20 61 |the code| takes a|
|00003160| 64 76 61 6e 74 61 67 65 | 20 6f 66 20 74 68 65 20 |dvantage| of the |
|00003170| 66 61 63 74 20 74 68 61 | 74 20 62 6f 74 68 20 74 |fact tha|t both t|
|00003180| 68 65 20 66 72 6f 6e 74 | 20 61 6e 64 0d 20 2a 20 |he front| and. * |
|00003190| 72 65 61 72 20 70 6f 69 | 6e 74 65 72 73 20 63 61 |rear poi|nters ca|
|000031a0| 6e 27 74 20 77 72 61 70 | 20 6f 6e 20 74 68 65 20 |n't wrap| on the |
|000031b0| 73 61 6d 65 20 63 61 6c | 6c 20 62 79 20 6e 6f 74 |same cal|l by not|
|000031c0| 20 74 65 73 74 69 6e 67 | 20 74 68 65 20 72 65 61 | testing| the rea|
|000031d0| 72 0d 20 2a 20 70 6f 69 | 6e 74 65 72 20 69 66 20 |r. * poi|nter if |
|000031e0| 74 68 65 20 66 72 6f 6e | 74 20 6f 6e 65 20 68 61 |the fron|t one ha|
|000031f0| 73 20 77 72 61 70 70 65 | 64 2e 0d 20 2a 20 52 65 |s wrappe|d.. * Re|
|00003200| 74 75 72 6e 73 20 61 20 | 33 31 2d 62 69 74 20 72 |turns a |31-bit r|
|00003210| 61 6e 64 6f 6d 20 6e 75 | 6d 62 65 72 2e 0d 20 2a |andom nu|mber.. *|
|00003220| 2f 0d 0d 6c 6f 6e 67 20 | 72 61 6e 64 6f 6d 28 29 |/..long |random()|
|00003230| 0d 7b 0d 09 6c 6f 6e 67 | 09 09 69 3b 0d 0d 09 69 |.{..long|..i;...i|
|00003240| 66 28 20 20 72 61 6e 64 | 5f 74 79 70 65 20 20 3d |f( rand|_type =|
|00003250| 3d 20 20 54 59 50 45 5f | 30 20 20 29 20 20 7b 0d |= TYPE_|0 ) {.|
|00003260| 09 20 20 20 20 69 20 3d | 20 73 74 61 74 65 5b 30 |. i =| state[0|
|00003270| 5d 20 3d 20 28 20 73 74 | 61 74 65 5b 30 5d 2a 31 |] = ( st|ate[0]*1|
|00003280| 31 30 33 35 31 35 32 34 | 35 20 2b 20 31 32 33 34 |10351524|5 + 1234|
|00003290| 35 20 29 26 30 78 37 66 | 66 66 66 66 66 66 3b 0d |5 )&0x7f|ffffff;.|
|000032a0| 09 7d 0d 09 65 6c 73 65 | 20 20 7b 0d 09 20 20 20 |.}..else| {.. |
|000032b0| 20 2a 66 70 74 72 20 2b | 3d 20 2a 72 70 74 72 3b | *fptr +|= *rptr;|
|000032c0| 0d 09 20 20 20 20 69 20 | 3d 20 28 2a 66 70 74 72 |.. i |= (*fptr|
|000032d0| 20 3e 3e 20 31 29 26 30 | 78 37 66 66 66 66 66 66 | >> 1)&0|x7ffffff|
|000032e0| 66 3b 09 2f 2a 20 63 68 | 75 63 6b 69 6e 67 20 6c |f;./* ch|ucking l|
|000032f0| 65 61 73 74 20 72 61 6e | 64 6f 6d 20 62 69 74 20 |east ran|dom bit |
|00003300| 2a 2f 0d 09 20 20 20 20 | 69 66 28 20 20 2b 2b 66 |*/.. |if( ++f|
|00003310| 70 74 72 20 20 3e 3d 20 | 20 65 6e 64 5f 70 74 72 |ptr >= | end_ptr|
|00003320| 20 20 29 20 20 7b 0d 09 | 09 66 70 74 72 20 3d 20 | ) {..|.fptr = |
|00003330| 73 74 61 74 65 3b 0d 09 | 09 2b 2b 72 70 74 72 3b |state;..|.++rptr;|
|00003340| 0d 09 20 20 20 20 7d 0d | 09 20 20 20 20 65 6c 73 |.. }.|. els|
|00003350| 65 20 20 7b 0d 09 09 69 | 66 28 20 20 2b 2b 72 70 |e {...i|f( ++rp|
|00003360| 74 72 20 20 3e 3d 20 20 | 65 6e 64 5f 70 74 72 20 |tr >= |end_ptr |
|00003370| 20 29 20 20 72 70 74 72 | 20 3d 20 73 74 61 74 65 | ) rptr| = state|
|00003380| 3b 0d 09 20 20 20 20 7d | 0d 09 7d 0d 09 72 65 74 |;.. }|..}..ret|
|00003390| 75 72 6e 28 20 69 20 29 | 3b 0d 7d 0d 0d 76 6f 69 |urn( i )|;.}..voi|
|000033a0| 64 20 49 6e 69 74 52 61 | 6e 64 6f 6d 28 76 6f 69 |d InitRa|ndom(voi|
|000033b0| 64 29 3b 0d 0d 76 6f 69 | 64 20 49 6e 69 74 52 61 |d);..voi|d InitRa|
|000033c0| 6e 64 6f 6d 28 29 0d 09 | 7b 0d 09 0d 09 66 70 74 |ndom()..|{....fpt|
|000033d0| 72 09 09 09 3d 20 26 72 | 61 6e 64 74 62 6c 5b 20 |r...= &r|andtbl[ |
|000033e0| 53 45 50 5f 33 20 2b 20 | 31 20 5d 3b 0d 09 72 70 |SEP_3 + |1 ];..rp|
|000033f0| 74 72 09 09 09 3d 20 26 | 72 61 6e 64 74 62 6c 5b |tr...= &|randtbl[|
|00003400| 20 31 20 5d 3b 0d 09 73 | 74 61 74 65 09 09 09 3d | 1 ];..s|tate...=|
|00003410| 20 26 72 61 6e 64 74 62 | 6c 5b 20 31 20 5d 3b 0d | &randtb|l[ 1 ];.|
|00003420| 09 65 6e 64 5f 70 74 72 | 09 09 3d 20 26 72 61 6e |.end_ptr|..= &ran|
|00003430| 64 74 62 6c 5b 20 44 45 | 47 5f 33 20 2b 20 31 20 |dtbl[ DE|G_3 + 1 |
|00003440| 5d 3b 0d 09 7d 00 00 00 | 00 00 00 00 00 00 00 00 |];..}...|........|
|00003450| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00003460| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00003470| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00003480| 00 00 01 00 00 00 01 30 | 00 00 00 30 00 00 00 82 |.......0|...0....|
|00003490| 79 20 6e 6f 74 20 74 65 | 73 74 69 6e 67 20 74 68 |y not te|sting th|
|000034a0| 65 20 72 65 61 72 0d 20 | 2a 20 70 6f 69 6e 74 65 |e rear. |* pointe|
|000034b0| 08 52 41 4e 44 4f 4d 2e | 43 00 02 00 00 00 54 45 |.RANDOM.|C.....TE|
|000034c0| 58 54 54 4f 50 43 01 00 | 00 d2 00 00 00 00 00 00 |XTTOPC..|........|
|000034d0| 00 00 54 45 58 54 54 4f | 50 43 01 00 00 d2 00 00 |..TEXTTO|PC......|
|000034e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000034f0| 00 00 a4 3c af e8 00 00 | 33 c5 00 00 01 b2 61 6e |...<....|3.....an|
|00003500| 64 6f 6d 28 29 0d 7b 0d | 09 6c 6f 6e 67 09 09 69 |dom().{.|.long..i|
|00003510| 3b 0d 0d 09 69 66 28 20 | 20 72 61 6e 64 5f 74 79 |;...if( | rand_ty|
|00003520| 70 65 20 20 3d 3d 20 20 | 54 59 50 45 5f 30 20 20 |pe == |TYPE_0 |
|00003530| 29 20 20 7b 0d 09 20 20 | 20 20 69 20 3d 20 73 74 |) {.. | i = st|
|00003540| 61 74 65 5b 30 5d 20 3d | 20 28 20 73 74 61 74 65 |ate[0] =| ( state|
|00003550| 5b 30 5d 2a 31 31 30 33 | 35 31 35 32 34 35 20 2b |[0]*1103|515245 +|
|00003560| 20 31 32 33 34 35 20 29 | 26 30 78 37 66 66 66 66 | 12345 )|&0x7ffff|
|00003570| 66 66 66 3b 0d 09 7d 0d | 09 65 6c 73 65 20 20 7b |fff;..}.|.else {|
|00003580| 00 00 00 02 00 00 00 00 | 00 04 00 06 00 04 00 00 |........|........|
|00003590| 00 0a 00 09 06 4d 6f 6e | 61 63 6f 00 00 00 00 04 |.....Mon|aco.....|
|000035a0| ab 1f a0 00 00 00 00 08 | 00 46 00 52 02 95 02 32 |........|.F.R...2|
|000035b0| 00 00 01 00 00 00 01 30 | 00 00 00 30 00 00 00 82 |.......0|...0....|
|000035c0| 00 ad c5 d4 13 1a 00 00 | 00 1c 00 82 00 04 45 51 |........|......EQ|
|000035d0| 45 44 00 00 00 2a 45 54 | 41 42 00 00 00 36 45 46 |ED...*ET|AB...6EF|
|000035e0| 4e 54 00 00 00 42 4a 41 | 47 5a 00 00 00 4e 57 53 |NT...BJA|GZ...NWS|
|000035f0| 49 5a 00 00 00 5a 03 eb | ff ff 00 00 00 00 00 00 |IZ...Z..|........|
|00003600| 00 00 03 ec ff ff 00 00 | 00 06 00 ad c4 74 03 eb |........|.....t..|
|00003610| ff ff 00 00 00 0e 00 ad | c4 90 03 ed ff ff 00 00 |........|........|
|00003620| 00 1c 00 ad c3 bc 03 ee | ff ff 00 00 00 24 00 ad |........|.....$..|
|00003630| c3 40 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |.@......|........|
|00003640| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00003650| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00003660| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00003670| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
+--------+-------------------------+-------------------------+--------+--------+