home *** CD-ROM | disk | FTP | other *** search
open in:
MacOS 8.1
|
Win98
|
DOS
view JSON data
|
view as text
This file was processed as: SHell self-extracting ARchive
(archive/shar).
You can browse this item here: mrandom
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| SHell self-extracting ARchive (archive/shar)
| magic
| Supported |
1%
| dexvert
| Text File (text/txt)
| fallback
| Supported |
100%
| file
| makefile script, ASCII text
| default
| |
100%
| checkBytes
| Printable ASCII
| default
| |
100%
| perlTextCheck
| Likely Text (Perl)
| default
| |
100%
| siegfried
| fmt/329 Shell Archive Format
| default
| |
100%
| detectItEasy
| Format: plain text[LF]
| default (weak)
|
|
hex view+--------+-------------------------+-------------------------+--------+--------+
|00000000| 4e 65 77 73 67 72 6f 75 | 70 73 3a 20 63 6f 6d 70 |Newsgrou|ps: comp|
|00000010| 2e 73 6f 75 72 63 65 73 | 2e 75 6e 69 78 0a 50 61 |.sources|.unix.Pa|
|00000020| 74 68 3a 20 70 61 2e 64 | 65 63 2e 63 6f 6d 21 76 |th: pa.d|ec.com!v|
|00000030| 69 78 69 65 0a 46 72 6f | 6d 3a 20 76 69 78 69 65 |ixie.Fro|m: vixie|
|00000040| 40 70 61 2e 64 65 63 2e | 63 6f 6d 20 28 50 61 75 |@pa.dec.|com (Pau|
|00000050| 6c 20 56 69 78 69 65 29 | 0a 53 75 62 6a 65 63 74 |l Vixie)|.Subject|
|00000060| 3a 20 76 32 35 69 30 32 | 33 3a 20 41 20 72 61 6e |: v25i02|3: A ran|
|00000070| 64 6f 6d 20 6e 75 6d 62 | 65 72 20 67 65 6e 65 72 |dom numb|er gener|
|00000080| 61 74 6f 72 20 77 69 74 | 68 20 70 65 72 73 69 73 |ator wit|h persis|
|00000090| 74 65 6e 74 20 73 74 61 | 74 65 0a 4d 65 73 73 61 |tent sta|te.Messa|
|000000a0| 67 65 2d 49 44 3a 20 3c | 31 39 39 31 44 65 63 31 |ge-ID: <|1991Dec1|
|000000b0| 34 2e 30 33 33 34 30 37 | 2e 32 36 33 34 33 40 50 |4.033407|.26343@P|
|000000c0| 41 2e 64 65 63 2e 63 6f | 6d 3e 0a 53 65 6e 64 65 |A.dec.co|m>.Sende|
|000000d0| 72 3a 20 6e 65 77 73 40 | 50 41 2e 64 65 63 2e 63 |r: news@|PA.dec.c|
|000000e0| 6f 6d 20 28 4e 65 77 73 | 29 0a 4f 72 67 61 6e 69 |om (News|).Organi|
|000000f0| 7a 61 74 69 6f 6e 3a 20 | 44 45 43 20 50 61 6c 6f |zation: |DEC Palo|
|00000100| 20 41 6c 74 6f 0a 44 61 | 74 65 3a 20 53 61 74 2c | Alto.Da|te: Sat,|
|00000110| 20 31 34 20 44 65 63 20 | 39 31 20 30 33 3a 33 34 | 14 Dec |91 03:34|
|00000120| 3a 30 37 20 47 4d 54 0a | 41 70 70 72 6f 76 65 64 |:07 GMT.|Approved|
|00000130| 3a 20 76 69 78 69 65 40 | 70 61 2e 64 65 63 2e 63 |: vixie@|pa.dec.c|
|00000140| 6f 6d 0a 4c 69 6e 65 73 | 3a 20 38 36 38 0a 0a 53 |om.Lines|: 868..S|
|00000150| 75 62 6d 69 74 74 65 64 | 2d 42 79 3a 20 43 6c 61 |ubmitted|-By: Cla|
|00000160| 72 6b 20 54 68 6f 6d 62 | 6f 72 73 6f 6e 20 3c 63 |rk Thomb|orson <c|
|00000170| 74 68 6f 6d 62 6f 72 40 | 67 77 2e 64 2e 75 6d 6e |thombor@|gw.d.umn|
|00000180| 2e 65 64 75 3e 0a 50 6f | 73 74 69 6e 67 2d 4e 75 |.edu>.Po|sting-Nu|
|00000190| 6d 62 65 72 3a 20 56 6f | 6c 75 6d 65 20 32 35 2c |mber: Vo|lume 25,|
|000001a0| 20 49 73 73 75 65 20 32 | 33 0a 41 72 63 68 69 76 | Issue 2|3.Archiv|
|000001b0| 65 2d 4e 61 6d 65 3a 20 | 6d 72 61 6e 64 6f 6d 0a |e-Name: |mrandom.|
|000001c0| 0a 49 20 77 72 6f 74 65 | 20 74 68 69 73 20 70 61 |.I wrote| this pa|
|000001d0| 63 6b 61 67 65 20 74 6f | 20 6f 76 65 72 63 6f 6d |ckage to| overcom|
|000001e0| 65 20 73 6f 6d 65 20 74 | 72 6f 75 62 6c 65 73 20 |e some t|roubles |
|000001f0| 49 20 68 61 64 20 77 69 | 74 68 20 74 68 65 20 72 |I had wi|th the r|
|00000200| 61 6e 64 6f 6d 28 29 20 | 0a 70 61 63 6b 61 67 65 |andom() |.package|
|00000210| 2e 20 20 49 20 68 61 64 | 20 62 65 65 6e 20 73 61 |. I had| been sa|
|00000220| 76 69 6e 67 20 72 61 6e | 64 6f 6d 28 29 27 73 20 |ving ran|dom()'s |
|00000230| 73 74 61 74 65 20 74 61 | 62 6c 65 20 74 6f 20 61 |state ta|ble to a|
|00000240| 20 64 69 73 6b 20 66 69 | 6c 65 2c 20 74 68 65 6e | disk fi|le, then|
|00000250| 0a 72 65 73 74 61 72 74 | 69 6e 67 20 74 68 65 20 |.restart|ing the |
|00000260| 72 61 6e 64 6f 6d 20 73 | 65 71 75 65 6e 63 65 20 |random s|equence |
|00000270| 69 6e 20 74 68 65 20 6e | 65 78 74 20 70 72 6f 67 |in the n|ext prog|
|00000280| 72 61 6d 20 72 75 6e 2e | 20 20 49 20 64 69 73 63 |ram run.| I disc|
|00000290| 6f 76 65 72 65 64 20 73 | 6f 6d 65 0a 73 65 72 69 |overed s|ome.seri|
|000002a0| 6f 75 73 6c 79 20 6e 6f | 6e 2d 72 61 6e 64 6f 6d |ously no|n-random|
|000002b0| 20 62 65 68 61 76 69 6f | 72 20 69 6e 20 74 68 65 | behavio|r in the|
|000002c0| 20 6e 75 6d 62 65 72 73 | 20 72 65 73 75 6c 74 69 | numbers| resulti|
|000002d0| 6e 67 20 66 72 6f 6d 20 | 74 68 69 73 20 70 72 61 |ng from |this pra|
|000002e0| 63 74 69 63 65 2e 0a 46 | 75 72 74 68 65 72 20 69 |ctice..F|urther i|
|000002f0| 6e 76 65 73 74 69 67 61 | 74 69 6f 6e 20 28 69 6e |nvestiga|tion (in|
|00000300| 63 6c 75 64 69 6e 67 20 | 65 78 61 6d 69 6e 61 74 |cluding |examinat|
|00000310| 69 6f 6e 20 6f 66 20 74 | 68 65 20 6f 62 6a 65 63 |ion of t|he objec|
|00000320| 74 20 63 6f 64 65 20 66 | 6f 72 0a 72 61 6e 64 6f |t code f|or.rando|
|00000330| 6d 28 29 20 2d 2d 20 70 | 61 69 6e 66 75 6c 21 29 |m() -- p|ainful!)|
|00000340| 20 73 68 6f 77 65 64 20 | 6d 65 20 74 68 61 74 20 | showed |me that |
|00000350| 69 74 20 69 73 20 6e 65 | 63 65 73 73 61 72 79 20 |it is ne|cessary |
|00000360| 74 6f 20 63 6f 75 6e 74 | 20 74 68 65 20 6e 75 6d |to count| the num|
|00000370| 62 65 72 20 6f 66 0a 63 | 61 6c 6c 73 20 74 6f 20 |ber of.c|alls to |
|00000380| 72 61 6e 64 6f 6d 28 29 | 20 69 6e 20 6f 72 64 65 |random()| in orde|
|00000390| 72 20 74 6f 20 73 61 66 | 65 6c 79 20 72 65 73 74 |r to saf|ely rest|
|000003a0| 61 72 74 20 69 74 2e 20 | 20 48 65 6e 63 65 20 74 |art it. | Hence t|
|000003b0| 68 65 20 65 6e 63 6c 6f | 73 65 64 20 63 6f 64 65 |he enclo|sed code|
|000003c0| 2e 0a 0a 5b 20 49 20 61 | 64 64 65 64 20 61 6c 6c |...[ I a|dded all|
|000003d0| 2c 20 63 6c 65 61 6e 2c | 20 61 6e 64 20 69 6e 73 |, clean,| and ins|
|000003e0| 74 61 6c 6c 20 74 61 72 | 67 65 74 73 20 74 6f 20 |tall tar|gets to |
|000003f0| 74 68 65 20 4d 61 6b 65 | 66 69 6c 65 2e 20 20 2d |the Make|file. -|
|00000400| 2d 76 69 78 20 5d 0a 0a | 23 21 20 2f 62 69 6e 2f |-vix ]..|#! /bin/|
|00000410| 73 68 0a 23 20 54 68 69 | 73 20 69 73 20 61 20 73 |sh.# Thi|s is a s|
|00000420| 68 65 6c 6c 20 61 72 63 | 68 69 76 65 2e 20 20 52 |hell arc|hive. R|
|00000430| 65 6d 6f 76 65 20 61 6e | 79 74 68 69 6e 67 20 62 |emove an|ything b|
|00000440| 65 66 6f 72 65 20 74 68 | 69 73 20 6c 69 6e 65 2c |efore th|is line,|
|00000450| 20 74 68 65 6e 20 75 6e | 70 61 63 6b 0a 23 20 69 | then un|pack.# i|
|00000460| 74 20 62 79 20 73 61 76 | 69 6e 67 20 69 74 20 69 |t by sav|ing it i|
|00000470| 6e 74 6f 20 61 20 66 69 | 6c 65 20 61 6e 64 20 74 |nto a fi|le and t|
|00000480| 79 70 69 6e 67 20 22 73 | 68 20 66 69 6c 65 22 2e |yping "s|h file".|
|00000490| 20 20 54 6f 20 6f 76 65 | 72 77 72 69 74 65 20 65 | To ove|rwrite e|
|000004a0| 78 69 73 74 69 6e 67 0a | 23 20 66 69 6c 65 73 2c |xisting.|# files,|
|000004b0| 20 74 79 70 65 20 22 73 | 68 20 66 69 6c 65 20 2d | type "s|h file -|
|000004c0| 63 22 2e 20 20 59 6f 75 | 20 63 61 6e 20 61 6c 73 |c". You| can als|
|000004d0| 6f 20 66 65 65 64 20 74 | 68 69 73 20 61 73 20 73 |o feed t|his as s|
|000004e0| 74 61 6e 64 61 72 64 20 | 69 6e 70 75 74 20 76 69 |tandard |input vi|
|000004f0| 61 0a 23 20 75 6e 73 68 | 61 72 2c 20 6f 72 20 62 |a.# unsh|ar, or b|
|00000500| 79 20 74 79 70 69 6e 67 | 20 22 73 68 20 3c 66 69 |y typing| "sh <fi|
|00000510| 6c 65 22 2c 20 65 2e 67 | 2e 2e 20 20 49 66 20 74 |le", e.g|.. If t|
|00000520| 68 69 73 20 61 72 63 68 | 69 76 65 20 69 73 20 63 |his arch|ive is c|
|00000530| 6f 6d 70 6c 65 74 65 2c | 20 79 6f 75 0a 23 20 77 |omplete,| you.# w|
|00000540| 69 6c 6c 20 73 65 65 20 | 74 68 65 20 66 6f 6c 6c |ill see |the foll|
|00000550| 6f 77 69 6e 67 20 6d 65 | 73 73 61 67 65 20 61 74 |owing me|ssage at|
|00000560| 20 74 68 65 20 65 6e 64 | 3a 0a 23 09 09 22 45 6e | the end|:.#.."En|
|00000570| 64 20 6f 66 20 61 72 63 | 68 69 76 65 20 31 20 28 |d of arc|hive 1 (|
|00000580| 6f 66 20 31 29 2e 22 0a | 23 20 43 6f 6e 74 65 6e |of 1).".|# Conten|
|00000590| 74 73 3a 20 20 4d 41 4e | 49 46 45 53 54 20 4d 61 |ts: MAN|IFEST Ma|
|000005a0| 6b 65 66 69 6c 65 20 52 | 45 41 44 4d 45 20 6d 72 |kefile R|EADME mr|
|000005b0| 61 6e 64 6f 6d 2e 33 20 | 6d 72 61 6e 64 6f 6d 2e |andom.3 |mrandom.|
|000005c0| 63 20 6d 72 61 6e 64 6f | 6d 2e 68 0a 23 20 20 20 |c mrando|m.h.# |
|000005d0| 6d 72 74 65 73 74 2e 63 | 0a 23 20 57 72 61 70 70 |mrtest.c|.# Wrapp|
|000005e0| 65 64 20 62 79 20 76 69 | 78 69 65 40 63 6f 67 6e |ed by vi|xie@cogn|
|000005f0| 69 74 69 6f 6e 2e 70 61 | 2e 64 65 63 2e 63 6f 6d |ition.pa|.dec.com|
|00000600| 20 6f 6e 20 46 72 69 20 | 44 65 63 20 31 33 20 31 | on Fri |Dec 13 1|
|00000610| 34 3a 32 38 3a 33 31 20 | 31 39 39 31 0a 50 41 54 |4:28:31 |1991.PAT|
|00000620| 48 3d 2f 62 69 6e 3a 2f | 75 73 72 2f 62 69 6e 3a |H=/bin:/|usr/bin:|
|00000630| 2f 75 73 72 2f 75 63 62 | 20 3b 20 65 78 70 6f 72 |/usr/ucb| ; expor|
|00000640| 74 20 50 41 54 48 0a 69 | 66 20 74 65 73 74 20 2d |t PATH.i|f test -|
|00000650| 66 20 27 4d 41 4e 49 46 | 45 53 54 27 20 2d 61 20 |f 'MANIF|EST' -a |
|00000660| 22 24 7b 31 7d 22 20 21 | 3d 20 22 2d 63 22 20 3b |"${1}" !|= "-c" ;|
|00000670| 20 74 68 65 6e 20 0a 20 | 20 65 63 68 6f 20 73 68 | then . | echo sh|
|00000680| 61 72 3a 20 57 69 6c 6c | 20 6e 6f 74 20 63 6c 6f |ar: Will| not clo|
|00000690| 62 62 65 72 20 65 78 69 | 73 74 69 6e 67 20 66 69 |bber exi|sting fi|
|000006a0| 6c 65 20 5c 22 27 4d 41 | 4e 49 46 45 53 54 27 5c |le \"'MA|NIFEST'\|
|000006b0| 22 0a 65 6c 73 65 0a 65 | 63 68 6f 20 73 68 61 72 |".else.e|cho shar|
|000006c0| 3a 20 45 78 74 72 61 63 | 74 69 6e 67 20 5c 22 27 |: Extrac|ting \"'|
|000006d0| 4d 41 4e 49 46 45 53 54 | 27 5c 22 20 5c 28 33 33 |MANIFEST|'\" \(33|
|000006e0| 31 20 63 68 61 72 61 63 | 74 65 72 73 5c 29 0a 73 |1 charac|ters\).s|
|000006f0| 65 64 20 22 73 2f 5e 58 | 2f 2f 22 20 3e 27 4d 41 |ed "s/^X|//" >'MA|
|00000700| 4e 49 46 45 53 54 27 20 | 3c 3c 27 45 4e 44 5f 4f |NIFEST' |<<'END_O|
|00000710| 46 5f 46 49 4c 45 27 0a | 58 20 20 20 46 69 6c 65 |F_FILE'.|X File|
|00000720| 20 4e 61 6d 65 09 09 41 | 72 63 68 69 76 65 20 23 | Name..A|rchive #|
|00000730| 09 44 65 73 63 72 69 70 | 74 69 6f 6e 0a 58 2d 2d |.Descrip|tion.X--|
|00000740| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00000750| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00000760| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00000770| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 0a 58 20 4d 41 4e 49 |--------|-.X MANI|
|00000780| 46 45 53 54 20 20 20 20 | 20 20 20 20 20 20 20 20 |FEST | |
|00000790| 20 20 20 20 20 20 20 31 | 09 54 68 69 73 20 73 68 | 1|.This sh|
|000007a0| 69 70 70 69 6e 67 20 6c | 69 73 74 0a 58 20 4d 61 |ipping l|ist.X Ma|
|000007b0| 6b 65 66 69 6c 65 20 20 | 20 20 20 20 20 20 20 20 |kefile | |
|000007c0| 20 20 20 20 20 20 20 20 | 20 31 09 0a 58 20 52 45 | | 1..X RE|
|000007d0| 41 44 4d 45 20 20 20 20 | 20 20 20 20 20 20 20 20 |ADME | |
|000007e0| 20 20 20 20 20 20 20 20 | 20 31 09 0a 58 20 6d 72 | | 1..X mr|
|000007f0| 61 6e 64 6f 6d 2e 33 20 | 20 20 20 20 20 20 20 20 |andom.3 | |
|00000800| 20 20 20 20 20 20 20 20 | 20 31 09 0a 58 20 6d 72 | | 1..X mr|
|00000810| 61 6e 64 6f 6d 2e 63 20 | 20 20 20 20 20 20 20 20 |andom.c | |
|00000820| 20 20 20 20 20 20 20 20 | 20 31 09 0a 58 20 6d 72 | | 1..X mr|
|00000830| 61 6e 64 6f 6d 2e 68 20 | 20 20 20 20 20 20 20 20 |andom.h | |
|00000840| 20 20 20 20 20 20 20 20 | 20 31 09 0a 58 20 6d 72 | | 1..X mr|
|00000850| 74 65 73 74 2e 63 20 20 | 20 20 20 20 20 20 20 20 |test.c | |
|00000860| 20 20 20 20 20 20 20 20 | 20 31 09 0a 45 4e 44 5f | | 1..END_|
|00000870| 4f 46 5f 46 49 4c 45 0a | 69 66 20 74 65 73 74 20 |OF_FILE.|if test |
|00000880| 33 33 31 20 2d 6e 65 20 | 60 77 63 20 2d 63 20 3c |331 -ne |`wc -c <|
|00000890| 27 4d 41 4e 49 46 45 53 | 54 27 60 3b 20 74 68 65 |'MANIFES|T'`; the|
|000008a0| 6e 0a 20 20 20 20 65 63 | 68 6f 20 73 68 61 72 3a |n. ec|ho shar:|
|000008b0| 20 5c 22 27 4d 41 4e 49 | 46 45 53 54 27 5c 22 20 | \"'MANI|FEST'\" |
|000008c0| 75 6e 70 61 63 6b 65 64 | 20 77 69 74 68 20 77 72 |unpacked| with wr|
|000008d0| 6f 6e 67 20 73 69 7a 65 | 21 0a 66 69 0a 23 20 65 |ong size|!.fi.# e|
|000008e0| 6e 64 20 6f 66 20 27 4d | 41 4e 49 46 45 53 54 27 |nd of 'M|ANIFEST'|
|000008f0| 0a 66 69 0a 69 66 20 74 | 65 73 74 20 2d 66 20 27 |.fi.if t|est -f '|
|00000900| 4d 61 6b 65 66 69 6c 65 | 27 20 2d 61 20 22 24 7b |Makefile|' -a "${|
|00000910| 31 7d 22 20 21 3d 20 22 | 2d 63 22 20 3b 20 74 68 |1}" != "|-c" ; th|
|00000920| 65 6e 20 0a 20 20 65 63 | 68 6f 20 73 68 61 72 3a |en . ec|ho shar:|
|00000930| 20 57 69 6c 6c 20 6e 6f | 74 20 63 6c 6f 62 62 65 | Will no|t clobbe|
|00000940| 72 20 65 78 69 73 74 69 | 6e 67 20 66 69 6c 65 20 |r existi|ng file |
|00000950| 5c 22 27 4d 61 6b 65 66 | 69 6c 65 27 5c 22 0a 65 |\"'Makef|ile'\".e|
|00000960| 6c 73 65 0a 65 63 68 6f | 20 73 68 61 72 3a 20 45 |lse.echo| shar: E|
|00000970| 78 74 72 61 63 74 69 6e | 67 20 5c 22 27 4d 61 6b |xtractin|g \"'Mak|
|00000980| 65 66 69 6c 65 27 5c 22 | 20 5c 28 32 36 37 20 63 |efile'\"| \(267 c|
|00000990| 68 61 72 61 63 74 65 72 | 73 5c 29 0a 73 65 64 20 |haracter|s\).sed |
|000009a0| 22 73 2f 5e 58 2f 2f 22 | 20 3e 27 4d 61 6b 65 66 |"s/^X//"| >'Makef|
|000009b0| 69 6c 65 27 20 3c 3c 27 | 45 4e 44 5f 4f 46 5f 46 |ile' <<'|END_OF_F|
|000009c0| 49 4c 45 27 0a 43 46 4c | 41 47 53 3d 20 2d 4f 0a |ILE'.CFL|AGS= -O.|
|000009d0| 58 0a 61 6c 6c 3a 20 6d | 72 74 65 73 74 0a 58 0a |X.all: m|rtest.X.|
|000009e0| 63 6c 65 61 6e 3a 0a 58 | 09 2d 72 6d 20 2a 2e 6f |clean:.X|.-rm *.o|
|000009f0| 0a 58 09 2d 72 6d 20 6d | 72 74 65 73 74 0a 58 0a |.X.-rm m|rtest.X.|
|00000a00| 69 6e 73 74 61 6c 6c 3a | 3b 20 40 2d 65 63 68 6f |install:|; @-echo|
|00000a10| 20 22 6a 75 73 74 20 6c | 69 6e 6b 20 6d 72 61 6e | "just l|ink mran|
|00000a20| 64 6f 6d 2e 6f 20 69 6e | 74 6f 20 79 6f 75 72 20 |dom.o in|to your |
|00000a30| 6f 77 6e 20 70 72 6f 67 | 72 61 6d 73 20 61 73 20 |own prog|rams as |
|00000a40| 6e 65 65 64 65 64 2e 22 | 0a 58 0a 6d 72 74 65 73 |needed."|.X.mrtes|
|00000a50| 74 3a 20 6d 72 61 6e 64 | 6f 6d 2e 68 20 6d 72 61 |t: mrand|om.h mra|
|00000a60| 6e 64 6f 6d 2e 6f 20 6d | 72 74 65 73 74 2e 63 0a |ndom.o m|rtest.c.|
|00000a70| 58 09 63 63 20 24 28 43 | 46 4c 41 47 53 29 20 2d |X.cc $(C|FLAGS) -|
|00000a80| 6f 20 6d 72 74 65 73 74 | 20 6d 72 74 65 73 74 2e |o mrtest| mrtest.|
|00000a90| 63 20 6d 72 61 6e 64 6f | 6d 2e 6f 0a 58 0a 6d 72 |c mrando|m.o.X.mr|
|00000aa0| 61 6e 64 6f 6d 2e 6f 3a | 20 6d 72 61 6e 64 6f 6d |andom.o:| mrandom|
|00000ab0| 2e 68 20 6d 72 61 6e 64 | 6f 6d 2e 63 0a 58 09 63 |.h mrand|om.c.X.c|
|00000ac0| 63 20 24 28 43 46 4c 41 | 47 53 29 20 2d 63 20 6d |c $(CFLA|GS) -c m|
|00000ad0| 72 61 6e 64 6f 6d 2e 63 | 0a 45 4e 44 5f 4f 46 5f |random.c|.END_OF_|
|00000ae0| 46 49 4c 45 0a 69 66 20 | 74 65 73 74 20 32 36 37 |FILE.if |test 267|
|00000af0| 20 2d 6e 65 20 60 77 63 | 20 2d 63 20 3c 27 4d 61 | -ne `wc| -c <'Ma|
|00000b00| 6b 65 66 69 6c 65 27 60 | 3b 20 74 68 65 6e 0a 20 |kefile'`|; then. |
|00000b10| 20 20 20 65 63 68 6f 20 | 73 68 61 72 3a 20 5c 22 | echo |shar: \"|
|00000b20| 27 4d 61 6b 65 66 69 6c | 65 27 5c 22 20 75 6e 70 |'Makefil|e'\" unp|
|00000b30| 61 63 6b 65 64 20 77 69 | 74 68 20 77 72 6f 6e 67 |acked wi|th wrong|
|00000b40| 20 73 69 7a 65 21 0a 66 | 69 0a 23 20 65 6e 64 20 | size!.f|i.# end |
|00000b50| 6f 66 20 27 4d 61 6b 65 | 66 69 6c 65 27 0a 66 69 |of 'Make|file'.fi|
|00000b60| 0a 69 66 20 74 65 73 74 | 20 2d 66 20 27 52 45 41 |.if test| -f 'REA|
|00000b70| 44 4d 45 27 20 2d 61 20 | 22 24 7b 31 7d 22 20 21 |DME' -a |"${1}" !|
|00000b80| 3d 20 22 2d 63 22 20 3b | 20 74 68 65 6e 20 0a 20 |= "-c" ;| then . |
|00000b90| 20 65 63 68 6f 20 73 68 | 61 72 3a 20 57 69 6c 6c | echo sh|ar: Will|
|00000ba0| 20 6e 6f 74 20 63 6c 6f | 62 62 65 72 20 65 78 69 | not clo|bber exi|
|00000bb0| 73 74 69 6e 67 20 66 69 | 6c 65 20 5c 22 27 52 45 |sting fi|le \"'RE|
|00000bc0| 41 44 4d 45 27 5c 22 0a | 65 6c 73 65 0a 65 63 68 |ADME'\".|else.ech|
|00000bd0| 6f 20 73 68 61 72 3a 20 | 45 78 74 72 61 63 74 69 |o shar: |Extracti|
|00000be0| 6e 67 20 5c 22 27 52 45 | 41 44 4d 45 27 5c 22 20 |ng \"'RE|ADME'\" |
|00000bf0| 5c 28 31 36 36 32 20 63 | 68 61 72 61 63 74 65 72 |\(1662 c|haracter|
|00000c00| 73 5c 29 0a 73 65 64 20 | 22 73 2f 5e 58 2f 2f 22 |s\).sed |"s/^X//"|
|00000c10| 20 3e 27 52 45 41 44 4d | 45 27 20 3c 3c 27 45 4e | >'READM|E' <<'EN|
|00000c20| 44 5f 4f 46 5f 46 49 4c | 45 27 0a 49 20 77 72 6f |D_OF_FIL|E'.I wro|
|00000c30| 74 65 20 74 68 69 73 20 | 70 61 63 6b 61 67 65 20 |te this |package |
|00000c40| 74 6f 20 6f 76 65 72 63 | 6f 6d 65 20 73 6f 6d 65 |to overc|ome some|
|00000c50| 20 74 72 6f 75 62 6c 65 | 73 20 49 20 68 61 64 20 | trouble|s I had |
|00000c60| 77 69 74 68 20 74 68 65 | 20 72 61 6e 64 6f 6d 28 |with the| random(|
|00000c70| 29 20 0a 70 61 63 6b 61 | 67 65 2e 20 20 49 20 68 |) .packa|ge. I h|
|00000c80| 61 64 20 62 65 65 6e 20 | 73 61 76 69 6e 67 20 72 |ad been |saving r|
|00000c90| 61 6e 64 6f 6d 28 29 27 | 73 20 73 74 61 74 65 20 |andom()'|s state |
|00000ca0| 74 61 62 6c 65 20 74 6f | 20 61 20 64 69 73 6b 20 |table to| a disk |
|00000cb0| 66 69 6c 65 2c 20 74 68 | 65 6e 0a 72 65 73 74 61 |file, th|en.resta|
|00000cc0| 72 74 69 6e 67 20 74 68 | 65 20 72 61 6e 64 6f 6d |rting th|e random|
|00000cd0| 20 73 65 71 75 65 6e 63 | 65 20 69 6e 20 74 68 65 | sequenc|e in the|
|00000ce0| 20 6e 65 78 74 20 70 72 | 6f 67 72 61 6d 20 72 75 | next pr|ogram ru|
|00000cf0| 6e 2e 20 20 49 20 64 69 | 73 63 6f 76 65 72 65 64 |n. I di|scovered|
|00000d00| 20 73 6f 6d 65 0a 73 65 | 72 69 6f 75 73 6c 79 20 | some.se|riously |
|00000d10| 6e 6f 6e 2d 72 61 6e 64 | 6f 6d 20 62 65 68 61 76 |non-rand|om behav|
|00000d20| 69 6f 72 20 69 6e 20 74 | 68 65 20 6e 75 6d 62 65 |ior in t|he numbe|
|00000d30| 72 73 20 72 65 73 75 6c | 74 69 6e 67 20 66 72 6f |rs resul|ting fro|
|00000d40| 6d 20 74 68 69 73 20 70 | 72 61 63 74 69 63 65 2e |m this p|ractice.|
|00000d50| 0a 58 46 75 72 74 68 65 | 72 20 69 6e 76 65 73 74 |.XFurthe|r invest|
|00000d60| 69 67 61 74 69 6f 6e 20 | 28 69 6e 63 6c 75 64 69 |igation |(includi|
|00000d70| 6e 67 20 65 78 61 6d 69 | 6e 61 74 69 6f 6e 20 6f |ng exami|nation o|
|00000d80| 66 20 74 68 65 20 6f 62 | 6a 65 63 74 20 63 6f 64 |f the ob|ject cod|
|00000d90| 65 20 66 6f 72 0a 72 61 | 6e 64 6f 6d 28 29 20 2d |e for.ra|ndom() -|
|00000da0| 2d 20 70 61 69 6e 66 75 | 6c 21 29 20 73 68 6f 77 |- painfu|l!) show|
|00000db0| 65 64 20 6d 65 20 74 68 | 61 74 20 69 74 20 69 73 |ed me th|at it is|
|00000dc0| 20 6e 65 63 65 73 73 61 | 72 79 20 74 6f 20 63 6f | necessa|ry to co|
|00000dd0| 75 6e 74 20 74 68 65 20 | 6e 75 6d 62 65 72 20 6f |unt the |number o|
|00000de0| 66 0a 63 61 6c 6c 73 20 | 74 6f 20 72 61 6e 64 6f |f.calls |to rando|
|00000df0| 6d 28 29 20 69 6e 20 6f | 72 64 65 72 20 74 6f 20 |m() in o|rder to |
|00000e00| 73 61 66 65 6c 79 20 72 | 65 73 74 61 72 74 20 69 |safely r|estart i|
|00000e10| 74 2e 20 20 48 65 6e 63 | 65 20 74 68 65 20 65 6e |t. Henc|e the en|
|00000e20| 63 6c 6f 73 65 64 20 63 | 6f 64 65 2e 0a 58 0a 49 |closed c|ode..X.I|
|00000e30| 20 62 65 6c 69 65 76 65 | 20 72 61 6e 64 6f 6d 28 | believe| random(|
|00000e40| 29 2c 20 77 69 74 68 20 | 6d 79 20 6d 6f 64 69 66 |), with |my modif|
|00000e50| 69 63 61 74 69 6f 6e 73 | 2c 20 69 73 20 73 75 70 |ications|, is sup|
|00000e60| 65 72 69 6f 72 20 69 6e | 20 6d 61 6e 79 20 72 65 |erior in| many re|
|00000e70| 73 70 65 63 74 73 0a 74 | 6f 20 69 74 73 20 63 6f |spects.t|o its co|
|00000e80| 6d 70 65 74 69 74 69 6f | 6e 20 77 69 74 68 69 6e |mpetitio|n within|
|00000e90| 20 34 2e 33 62 73 64 20 | 55 6e 69 78 2c 20 6e 61 | 4.3bsd |Unix, na|
|00000ea0| 6d 65 6c 79 20 72 61 6e | 64 28 29 20 61 6e 64 20 |mely ran|d() and |
|00000eb0| 72 61 6e 64 34 38 28 29 | 2e 0a 54 68 6f 73 65 20 |rand48()|..Those |
|00000ec0| 67 65 6e 65 72 61 74 6f | 72 73 20 61 72 65 20 62 |generato|rs are b|
|00000ed0| 61 73 65 64 20 6f 6e 20 | 61 20 6d 75 6c 74 69 70 |ased on |a multip|
|00000ee0| 6c 69 63 61 74 69 76 65 | 20 63 6f 6e 67 72 75 65 |licative| congrue|
|00000ef0| 6e 74 69 61 6c 20 73 63 | 68 65 6d 65 2c 0a 77 68 |ntial sc|heme,.wh|
|00000f00| 69 63 68 20 6d 61 6b 65 | 73 20 74 68 65 6d 20 64 |ich make|s them d|
|00000f10| 69 66 66 69 63 75 6c 74 | 20 74 6f 20 75 73 65 20 |ifficult| to use |
|00000f20| 69 6e 20 61 70 70 6c 69 | 63 61 74 69 6f 6e 73 20 |in appli|cations |
|00000f30| 77 68 65 72 65 20 6f 6e | 65 20 69 73 20 67 65 6e |where on|e is gen|
|00000f40| 65 72 61 74 69 6e 67 0a | 70 6f 69 6e 74 73 20 75 |erating.|points u|
|00000f50| 6e 69 66 6f 72 6d 6c 79 | 20 64 69 73 74 72 69 62 |niformly| distrib|
|00000f60| 75 74 65 64 20 6f 6e 20 | 74 68 65 20 75 6e 69 74 |uted on |the unit|
|00000f70| 20 73 71 75 61 72 65 2e | 20 20 43 65 72 74 61 69 | square.| Certai|
|00000f80| 6e 6c 79 20 72 61 6e 64 | 28 29 20 68 61 73 0a 74 |nly rand|() has.t|
|00000f90| 68 65 20 70 72 6f 62 6c | 65 6d 20 74 68 61 74 20 |he probl|em that |
|00000fa0| 61 20 68 69 67 68 2d 72 | 65 73 6f 6c 75 74 69 6f |a high-r|esolutio|
|00000fb0| 6e 20 32 2d 64 20 70 6c | 6f 74 20 6f 66 20 74 68 |n 2-d pl|ot of th|
|00000fc0| 65 20 78 2d 79 20 70 6f | 69 6e 74 73 20 67 65 6e |e x-y po|ints gen|
|00000fd0| 65 72 61 74 65 64 20 62 | 79 0a 58 09 66 6f 72 20 |erated b|y.X.for |
|00000fe0| 28 69 3d 30 3b 20 69 3c | 6e 3b 20 69 2b 2b 29 20 |(i=0; i<|n; i++) |
|00000ff0| 7b 0a 58 09 20 20 78 5b | 69 5d 20 3d 20 72 61 6e |{.X. x[|i] = ran|
|00001000| 64 28 29 2f 4d 41 58 4c | 4f 4e 47 3b 0a 58 09 20 |d()/MAXL|ONG;.X. |
|00001010| 20 79 5b 69 5d 20 3d 20 | 72 61 6e 64 28 29 2f 4d | y[i] = |rand()/M|
|00001020| 41 58 4c 4f 4e 47 3b 0a | 58 09 7d 20 0a 77 69 6c |AXLONG;.|X.} .wil|
|00001030| 6c 20 73 68 6f 77 20 73 | 74 72 69 70 65 73 2e 20 |l show s|tripes. |
|00001040| 20 55 73 69 6e 67 20 72 | 61 6e 64 28 29 25 6d 20 | Using r|and()%m |
|00001050| 69 73 20 73 75 69 63 69 | 64 61 6c 2c 20 73 69 6e |is suici|dal, sin|
|00001060| 63 65 20 69 74 73 20 6c | 6f 77 2d 6f 72 64 65 72 |ce its l|ow-order|
|00001070| 20 62 69 74 73 0a 61 72 | 65 20 6b 6e 6f 77 6e 20 | bits.ar|e known |
|00001080| 74 6f 20 62 65 20 63 79 | 63 6c 69 63 2e 20 20 50 |to be cy|clic. P|
|00001090| 65 72 68 61 70 73 20 49 | 27 6d 20 73 65 6c 6c 69 |erhaps I|'m selli|
|000010a0| 6e 67 20 72 61 6e 64 34 | 38 28 29 20 73 68 6f 72 |ng rand4|8() shor|
|000010b0| 74 2c 20 73 69 6e 63 65 | 20 49 20 68 61 76 65 6e |t, since| I haven|
|000010c0| 27 74 0a 65 78 61 6d 69 | 6e 65 64 20 69 74 20 69 |'t.exami|ned it i|
|000010d0| 6e 20 64 65 74 61 69 6c | 3a 20 71 75 69 74 65 20 |n detail|: quite |
|000010e0| 70 6f 73 73 69 62 6c 79 | 20 69 74 73 20 63 6f 6e |possibly| its con|
|000010f0| 73 74 61 6e 74 73 20 77 | 65 72 65 20 63 68 6f 73 |stants w|ere chos|
|00001100| 65 6e 20 74 6f 20 6d 69 | 6e 69 6d 69 7a 65 0a 74 |en to mi|nimize.t|
|00001110| 68 65 20 73 65 70 61 72 | 61 74 69 6f 6e 20 62 65 |he separ|ation be|
|00001120| 74 77 65 65 6e 20 74 68 | 65 20 73 74 72 69 70 65 |tween th|e stripe|
|00001130| 73 20 69 6e 20 61 20 32 | 2d 64 20 70 6c 6f 74 2e |s in a 2|-d plot.|
|00001140| 0a 58 0a 54 6f 20 68 65 | 6c 70 20 79 6f 75 20 67 |.X.To he|lp you g|
|00001150| 65 74 20 73 74 61 72 74 | 65 64 2c 20 49 20 68 61 |et start|ed, I ha|
|00001160| 76 65 20 61 6c 73 6f 20 | 65 6e 63 6c 6f 73 65 64 |ve also |enclosed|
|00001170| 20 61 20 74 65 73 74 2d | 64 72 69 76 65 72 20 63 | a test-|driver c|
|00001180| 61 6c 6c 65 64 20 6d 72 | 74 65 73 74 2e 0a 58 0a |alled mr|test..X.|
|00001190| 50 6c 65 61 73 65 20 6c | 65 74 20 6d 65 20 6b 6e |Please l|et me kn|
|000011a0| 6f 77 20 69 66 20 79 6f | 75 20 66 69 6e 64 20 61 |ow if yo|u find a|
|000011b0| 6e 79 20 64 65 66 65 63 | 74 73 20 69 6e 20 74 68 |ny defec|ts in th|
|000011c0| 65 20 73 65 71 75 65 6e | 63 65 20 67 65 6e 65 72 |e sequen|ce gener|
|000011d0| 61 74 65 64 0a 62 79 20 | 74 68 65 20 64 65 66 61 |ated.by |the defa|
|000011e0| 75 6c 74 20 73 65 65 64 | 20 62 75 69 6c 74 20 69 |ult seed| built i|
|000011f0| 6e 74 6f 20 6d 72 74 65 | 73 74 2e 20 20 49 20 70 |nto mrte|st. I p|
|00001200| 69 63 6b 65 64 20 74 68 | 61 74 20 73 65 65 64 20 |icked th|at seed |
|00001210| 66 6f 72 0a 73 65 6e 74 | 69 6d 65 6e 74 61 6c 20 |for.sent|imental |
|00001220| 72 65 61 73 6f 6e 73 3a | 20 69 74 20 77 61 73 20 |reasons:| it was |
|00001230| 74 68 65 20 6c 61 73 74 | 20 6e 75 6d 62 65 72 20 |the last| number |
|00001240| 67 65 6e 65 72 61 74 65 | 64 20 62 79 20 6d 79 20 |generate|d by my |
|00001250| 6f 6c 64 2c 0a 61 6e 64 | 20 6e 6f 77 20 64 69 73 |old,.and| now dis|
|00001260| 63 72 65 64 69 74 65 64 | 2c 20 72 61 6e 64 6f 6d |credited|, random|
|00001270| 28 29 20 73 65 71 75 65 | 6e 63 65 2e 0a 58 0a 58 |() seque|nce..X.X|
|00001280| 09 09 09 09 09 09 43 6c | 61 72 6b 20 54 68 6f 6d |......Cl|ark Thom|
|00001290| 62 6f 72 73 6f 6e 0a 58 | 09 09 09 09 09 09 63 74 |borson.X|......ct|
|000012a0| 68 6f 6d 62 6f 72 40 67 | 77 2e 64 2e 75 6d 6e 2e |hombor@g|w.d.umn.|
|000012b0| 65 64 75 0a 45 4e 44 5f | 4f 46 5f 46 49 4c 45 0a |edu.END_|OF_FILE.|
|000012c0| 69 66 20 74 65 73 74 20 | 31 36 36 32 20 2d 6e 65 |if test |1662 -ne|
|000012d0| 20 60 77 63 20 2d 63 20 | 3c 27 52 45 41 44 4d 45 | `wc -c |<'README|
|000012e0| 27 60 3b 20 74 68 65 6e | 0a 20 20 20 20 65 63 68 |'`; then|. ech|
|000012f0| 6f 20 73 68 61 72 3a 20 | 5c 22 27 52 45 41 44 4d |o shar: |\"'READM|
|00001300| 45 27 5c 22 20 75 6e 70 | 61 63 6b 65 64 20 77 69 |E'\" unp|acked wi|
|00001310| 74 68 20 77 72 6f 6e 67 | 20 73 69 7a 65 21 0a 66 |th wrong| size!.f|
|00001320| 69 0a 23 20 65 6e 64 20 | 6f 66 20 27 52 45 41 44 |i.# end |of 'READ|
|00001330| 4d 45 27 0a 66 69 0a 69 | 66 20 74 65 73 74 20 2d |ME'.fi.i|f test -|
|00001340| 66 20 27 6d 72 61 6e 64 | 6f 6d 2e 33 27 20 2d 61 |f 'mrand|om.3' -a|
|00001350| 20 22 24 7b 31 7d 22 20 | 21 3d 20 22 2d 63 22 20 | "${1}" |!= "-c" |
|00001360| 3b 20 74 68 65 6e 20 0a | 20 20 65 63 68 6f 20 73 |; then .| echo s|
|00001370| 68 61 72 3a 20 57 69 6c | 6c 20 6e 6f 74 20 63 6c |har: Wil|l not cl|
|00001380| 6f 62 62 65 72 20 65 78 | 69 73 74 69 6e 67 20 66 |obber ex|isting f|
|00001390| 69 6c 65 20 5c 22 27 6d | 72 61 6e 64 6f 6d 2e 33 |ile \"'m|random.3|
|000013a0| 27 5c 22 0a 65 6c 73 65 | 0a 65 63 68 6f 20 73 68 |'\".else|.echo sh|
|000013b0| 61 72 3a 20 45 78 74 72 | 61 63 74 69 6e 67 20 5c |ar: Extr|acting \|
|000013c0| 22 27 6d 72 61 6e 64 6f | 6d 2e 33 27 5c 22 20 5c |"'mrando|m.3'\" \|
|000013d0| 28 37 35 35 33 20 63 68 | 61 72 61 63 74 65 72 73 |(7553 ch|aracters|
|000013e0| 5c 29 0a 73 65 64 20 22 | 73 2f 5e 58 2f 2f 22 20 |\).sed "|s/^X//" |
|000013f0| 3e 27 6d 72 61 6e 64 6f | 6d 2e 33 27 20 3c 3c 27 |>'mrando|m.3' <<'|
|00001400| 45 4e 44 5f 4f 46 5f 46 | 49 4c 45 27 0a 58 2e 54 |END_OF_F|ILE'.X.T|
|00001410| 48 20 4d 52 41 4e 44 4f | 4d 20 33 20 22 31 31 20 |H MRANDO|M 3 "11 |
|00001420| 53 65 70 74 65 6d 62 65 | 72 20 31 39 39 31 22 0a |Septembe|r 1991".|
|00001430| 58 2e 53 48 20 4e 41 4d | 45 0a 6d 72 61 6e 64 6f |X.SH NAM|E.mrando|
|00001440| 6d 2c 20 66 72 61 6e 64 | 6f 6d 2c 20 69 6e 69 74 |m, frand|om, init|
|00001450| 5f 72 6e 67 2c 20 73 61 | 76 65 5f 72 6e 67 2c 20 |_rng, sa|ve_rng, |
|00001460| 72 65 73 74 61 72 74 5f | 72 6e 67 2c 20 72 65 63 |restart_|rng, rec|
|00001470| 6f 6e 73 74 72 75 63 74 | 5f 72 6e 67 2c 20 64 65 |onstruct|_rng, de|
|00001480| 73 63 72 69 62 65 5f 72 | 6e 67 20 5c 2d 20 77 72 |scribe_r|ng \- wr|
|00001490| 61 70 70 65 72 73 20 66 | 6f 72 20 34 2e 33 62 73 |appers f|or 4.3bs|
|000014a0| 64 20 72 61 6e 64 6f 6d | 0a 58 2e 53 48 20 53 59 |d random|.X.SH SY|
|000014b0| 4e 4f 50 53 49 53 0a 58 | 2e 6e 66 0a 58 2e 42 20 |NOPSIS.X|.nf.X.B |
|000014c0| 6c 6f 6e 67 20 20 6d 72 | 61 6e 64 6f 6d 28 6d 29 |long mr|andom(m)|
|000014d0| 0a 58 2e 42 20 6c 6f 6e | 67 20 6d 3b 0a 58 2e 4c |.X.B lon|g m;.X.L|
|000014e0| 50 0a 58 2e 42 20 64 6f | 75 62 6c 65 20 66 72 61 |P.X.B do|uble fra|
|000014f0| 6e 64 6f 6d 28 29 0a 58 | 2e 4c 50 0a 58 2e 42 20 |ndom().X|.LP.X.B |
|00001500| 69 6e 74 20 69 6e 69 74 | 5f 72 6e 67 28 73 65 65 |int init|_rng(see|
|00001510| 64 2c 20 66 69 6c 65 6e | 61 6d 65 29 0a 58 2e 42 |d, filen|ame).X.B|
|00001520| 20 6c 6f 6e 67 20 73 65 | 65 64 3b 0a 58 2e 42 20 | long se|ed;.X.B |
|00001530| 63 68 61 72 20 2a 66 69 | 6c 65 6e 61 6d 65 3b 0a |char *fi|lename;.|
|00001540| 58 2e 4c 50 0a 58 2e 42 | 20 69 6e 74 20 20 73 61 |X.LP.X.B| int sa|
|00001550| 76 65 5f 72 6e 67 28 66 | 69 6c 65 6e 61 6d 65 29 |ve_rng(f|ilename)|
|00001560| 0a 58 2e 42 20 63 68 61 | 72 20 2a 66 69 6c 65 6e |.X.B cha|r *filen|
|00001570| 61 6d 65 3b 0a 58 2e 4c | 50 20 0a 58 2e 42 20 69 |ame;.X.L|P .X.B i|
|00001580| 6e 74 20 72 65 73 74 61 | 72 74 5f 72 6e 67 28 66 |nt resta|rt_rng(f|
|00001590| 69 6c 65 6e 61 6d 65 29 | 0a 58 2e 42 20 63 68 61 |ilename)|.X.B cha|
|000015a0| 72 20 2a 66 69 6c 65 6e | 61 6d 65 3b 0a 58 2e 4c |r *filen|ame;.X.L|
|000015b0| 50 0a 58 2e 42 20 76 6f | 69 64 20 72 65 63 6f 6e |P.X.B vo|id recon|
|000015c0| 73 74 72 75 63 74 5f 72 | 6e 67 28 73 65 65 64 2c |struct_r|ng(seed,|
|000015d0| 20 63 6f 75 6e 74 31 2c | 20 63 6f 75 6e 74 32 29 | count1,| count2)|
|000015e0| 0a 58 2e 42 20 6c 6f 6e | 67 20 73 65 65 64 3b 0a |.X.B lon|g seed;.|
|000015f0| 58 2e 42 20 6c 6f 6e 67 | 20 63 6f 75 6e 74 31 3b |X.B long| count1;|
|00001600| 0a 58 2e 42 20 6c 6f 6e | 67 20 63 6f 75 6e 74 32 |.X.B lon|g count2|
|00001610| 3b 0a 58 2e 4c 50 0a 58 | 2e 42 20 63 68 61 72 20 |;.X.LP.X|.B char |
|00001620| 20 2a 64 65 73 63 72 69 | 62 65 5f 72 6e 67 28 72 | *descri|be_rng(r|
|00001630| 6e 67 69 64 29 0a 58 2e | 42 20 63 68 61 72 20 20 |ngid).X.|B char |
|00001640| 72 6e 67 69 64 5b 52 4e | 47 49 44 53 54 52 4c 45 |rngid[RN|GIDSTRLE|
|00001650| 4e 5d 3b 0a 58 2e 66 69 | 0a 58 2e 49 58 20 20 22 |N];.X.fi|.X.IX "|
|00001660| 6d 72 61 6e 64 6f 6d 20 | 66 75 6e 63 74 69 6f 6e |mrandom |function|
|00001670| 22 20 20 22 22 20 20 22 | 5c 66 4c 6d 72 61 6e 64 |" "" "|\fLmrand|
|00001680| 6f 6d 5c 66 50 20 5c 28 | 65 6d 20 67 65 6e 65 72 |om\fP \(|em gener|
|00001690| 61 74 65 20 72 61 6e 64 | 6f 6d 20 69 6e 74 65 67 |ate rand|om integ|
|000016a0| 65 72 20 6d 6f 64 20 6d | 22 0a 58 2e 49 58 20 20 |er mod m|".X.IX |
|000016b0| 22 66 72 61 6e 64 6f 6d | 20 66 75 6e 63 74 69 6f |"frandom| functio|
|000016c0| 6e 22 20 20 22 22 20 20 | 22 5c 66 4c 66 72 61 6e |n" "" |"\fLfran|
|000016d0| 64 6f 6d 5c 66 50 20 5c | 28 65 6d 20 67 65 6e 65 |dom\fP \|(em gene|
|000016e0| 72 61 74 65 20 72 61 6e | 64 6f 6d 20 36 34 2d 62 |rate ran|dom 64-b|
|000016f0| 69 74 20 66 6c 6f 61 74 | 22 0a 58 2e 49 58 20 20 |it float|".X.IX |
|00001700| 22 69 6e 69 74 5f 72 6e | 67 20 66 75 6e 63 74 69 |"init_rn|g functi|
|00001710| 6f 6e 22 20 20 22 22 20 | 20 22 5c 66 4c 69 6e 69 |on" "" | "\fLini|
|00001720| 74 5f 72 6e 67 5c 66 50 | 20 5c 28 65 6d 20 69 6e |t_rng\fP| \(em in|
|00001730| 69 74 69 61 6c 69 7a 65 | 20 72 61 6e 64 6f 6d 20 |itialize| random |
|00001740| 67 65 6e 65 72 61 74 6f | 72 22 0a 58 2e 49 58 20 |generato|r".X.IX |
|00001750| 20 22 73 61 76 65 5f 72 | 6e 67 20 66 75 6e 63 74 | "save_r|ng funct|
|00001760| 69 6f 6e 22 20 20 22 22 | 20 22 5c 66 4c 73 61 76 |ion" ""| "\fLsav|
|00001770| 65 5f 72 6e 67 5c 66 50 | 20 5c 28 65 6d 20 73 61 |e_rng\fP| \(em sa|
|00001780| 76 65 20 72 61 6e 64 6f | 6d 20 67 65 6e 65 72 61 |ve rando|m genera|
|00001790| 74 6f 72 20 74 6f 20 66 | 69 6c 65 22 0a 58 2e 49 |tor to f|ile".X.I|
|000017a0| 58 20 20 22 72 65 73 74 | 61 72 74 5f 72 6e 67 20 |X "rest|art_rng |
|000017b0| 66 75 6e 63 74 69 6f 6e | 22 20 20 22 22 20 22 5c |function|" "" "\|
|000017c0| 66 4c 72 65 73 74 61 72 | 74 5f 72 6e 67 5c 66 50 |fLrestar|t_rng\fP|
|000017d0| 20 5c 28 65 6d 20 72 65 | 73 74 61 72 74 20 72 61 | \(em re|start ra|
|000017e0| 6e 64 6f 6d 20 67 65 6e | 65 72 61 74 6f 72 20 66 |ndom gen|erator f|
|000017f0| 72 6f 6d 20 66 69 6c 65 | 22 0a 58 2e 49 58 20 20 |rom file|".X.IX |
|00001800| 22 72 65 63 6f 6e 73 74 | 72 75 63 74 5f 72 6e 67 |"reconst|ruct_rng|
|00001810| 20 66 75 6e 63 74 69 6f | 6e 22 20 20 22 22 20 20 | functio|n" "" |
|00001820| 22 5c 66 4c 72 65 63 6f | 6e 73 74 72 75 63 74 5f |"\fLreco|nstruct_|
|00001830| 72 6e 67 5c 66 50 20 5c | 28 65 6d 20 72 65 73 74 |rng\fP \|(em rest|
|00001840| 6f 72 65 20 72 61 6e 64 | 6f 6d 20 67 65 6e 65 72 |ore rand|om gener|
|00001850| 61 74 6f 72 20 66 72 6f | 6d 20 28 73 65 65 64 2c |ator fro|m (seed,|
|00001860| 20 63 6f 75 6e 74 31 2c | 20 63 6f 75 6e 74 32 29 | count1,| count2)|
|00001870| 20 76 61 6c 75 65 73 22 | 0a 58 2e 49 58 20 20 22 | values"|.X.IX "|
|00001880| 64 65 73 63 72 69 62 65 | 5f 72 6e 67 20 66 75 6e |describe|_rng fun|
|00001890| 63 74 69 6f 6e 22 20 20 | 22 22 20 22 5c 66 4c 64 |ction" |"" "\fLd|
|000018a0| 65 73 63 72 69 62 65 5f | 72 6e 67 5c 66 50 20 5c |escribe_|rng\fP \|
|000018b0| 28 65 6d 20 63 6f 6e 73 | 74 72 75 63 74 20 73 68 |(em cons|truct sh|
|000018c0| 6f 72 74 20 73 74 72 69 | 6e 67 20 64 65 73 63 72 |ort stri|ng descr|
|000018d0| 69 62 69 6e 67 20 67 65 | 6e 65 72 61 74 6f 72 20 |ibing ge|nerator |
|000018e0| 73 74 61 74 65 22 20 0a | 58 2e 49 58 20 20 22 72 |state" .|X.IX "r|
|000018f0| 61 6e 64 6f 6d 20 6e 75 | 6d 62 65 72 20 67 65 6e |andom nu|mber gen|
|00001900| 65 72 61 74 6f 72 22 20 | 20 22 5c 66 4c 6d 72 61 |erator" | "\fLmra|
|00001910| 6e 64 6f 6d 5c 66 50 22 | 0a 58 2e 49 58 20 20 22 |ndom\fP"|.X.IX "|
|00001920| 72 61 6e 64 6f 6d 20 6e | 75 6d 62 65 72 20 67 65 |random n|umber ge|
|00001930| 6e 65 72 61 74 6f 72 22 | 20 20 22 5c 66 4c 66 72 |nerator"| "\fLfr|
|00001940| 61 6e 64 6f 6d 5c 66 50 | 22 0a 58 2e 49 58 20 20 |andom\fP|".X.IX |
|00001950| 22 72 61 6e 64 6f 6d 20 | 6e 75 6d 62 65 72 20 67 |"random |number g|
|00001960| 65 6e 65 72 61 74 6f 72 | 22 20 20 22 5c 66 4c 69 |enerator|" "\fLi|
|00001970| 6e 69 74 5f 72 6e 67 5c | 66 50 22 0a 58 2e 49 58 |nit_rng\|fP".X.IX|
|00001980| 20 20 22 72 61 6e 64 6f | 6d 20 6e 75 6d 62 65 72 | "rando|m number|
|00001990| 20 67 65 6e 65 72 61 74 | 6f 72 22 20 20 22 5c 66 | generat|or" "\f|
|000019a0| 4c 73 61 76 65 5f 72 6e | 67 5c 66 50 22 0a 58 2e |Lsave_rn|g\fP".X.|
|000019b0| 49 58 20 20 22 72 61 6e | 64 6f 6d 20 6e 75 6d 62 |IX "ran|dom numb|
|000019c0| 65 72 20 67 65 6e 65 72 | 61 74 6f 72 22 20 20 22 |er gener|ator" "|
|000019d0| 5c 66 4c 72 65 73 74 61 | 72 74 5f 72 6e 67 5c 66 |\fLresta|rt_rng\f|
|000019e0| 50 22 0a 58 2e 49 58 20 | 20 22 72 61 6e 64 6f 6d |P".X.IX | "random|
|000019f0| 20 6e 75 6d 62 65 72 20 | 67 65 6e 65 72 61 74 6f | number |generato|
|00001a00| 72 22 20 20 22 5c 66 4c | 72 65 63 6f 6e 73 74 72 |r" "\fL|reconstr|
|00001a10| 75 63 74 5f 72 6e 67 5c | 66 50 22 0a 58 2e 49 58 |uct_rng\|fP".X.IX|
|00001a20| 20 20 22 72 61 6e 64 6f | 6d 20 6e 75 6d 62 65 72 | "rando|m number|
|00001a30| 20 67 65 6e 65 72 61 74 | 6f 72 22 20 20 22 5c 66 | generat|or" "\f|
|00001a40| 4c 64 65 73 63 72 69 62 | 65 5f 72 6e 67 5c 66 50 |Ldescrib|e_rng\fP|
|00001a50| 22 0a 58 2e 49 58 20 20 | 22 67 65 6e 65 72 61 74 |".X.IX |"generat|
|00001a60| 65 20 72 61 6e 64 6f 6d | 20 6e 75 6d 62 65 72 73 |e random| numbers|
|00001a70| 22 20 20 22 5c 66 4c 6d | 72 61 6e 64 6f 6d 5c 66 |" "\fLm|random\f|
|00001a80| 50 22 0a 58 2e 49 58 20 | 20 22 67 65 6e 65 72 61 |P".X.IX | "genera|
|00001a90| 74 65 20 72 61 6e 64 6f | 6d 20 6e 75 6d 62 65 72 |te rando|m number|
|00001aa0| 73 22 20 20 22 5c 66 4c | 66 72 61 6e 64 6f 6d 5c |s" "\fL|frandom\|
|00001ab0| 66 50 22 0a 58 2e 49 58 | 20 20 22 67 65 6e 65 72 |fP".X.IX| "gener|
|00001ac0| 61 74 65 20 72 61 6e 64 | 6f 6d 20 6e 75 6d 62 65 |ate rand|om numbe|
|00001ad0| 72 73 22 20 20 22 5c 66 | 4c 69 6e 69 74 5f 72 6e |rs" "\f|Linit_rn|
|00001ae0| 67 5c 66 50 22 0a 58 2e | 49 58 20 20 22 67 65 6e |g\fP".X.|IX "gen|
|00001af0| 65 72 61 74 65 20 72 61 | 6e 64 6f 6d 20 6e 75 6d |erate ra|ndom num|
|00001b00| 62 65 72 73 22 20 20 22 | 5c 66 4c 73 61 76 65 5f |bers" "|\fLsave_|
|00001b10| 72 6e 67 5c 66 50 22 0a | 58 2e 49 58 20 20 22 67 |rng\fP".|X.IX "g|
|00001b20| 65 6e 65 72 61 74 65 20 | 72 61 6e 64 6f 6d 20 6e |enerate |random n|
|00001b30| 75 6d 62 65 72 73 22 20 | 20 22 5c 66 4c 72 65 73 |umbers" | "\fLres|
|00001b40| 74 61 72 74 5f 72 6e 67 | 5c 66 50 22 0a 58 2e 49 |tart_rng|\fP".X.I|
|00001b50| 58 20 20 22 67 65 6e 65 | 72 61 74 65 20 72 61 6e |X "gene|rate ran|
|00001b60| 64 6f 6d 20 6e 75 6d 62 | 65 72 73 22 20 20 22 5c |dom numb|ers" "\|
|00001b70| 66 4c 72 65 63 6f 6e 73 | 74 72 75 63 74 5f 72 6e |fLrecons|truct_rn|
|00001b80| 67 5c 66 50 22 0a 58 2e | 49 58 20 20 22 67 65 6e |g\fP".X.|IX "gen|
|00001b90| 65 72 61 74 65 20 72 61 | 6e 64 6f 6d 20 6e 75 6d |erate ra|ndom num|
|00001ba0| 62 65 72 73 22 20 20 22 | 5c 66 4c 64 65 73 63 72 |bers" "|\fLdescr|
|00001bb0| 69 62 65 5f 72 6e 67 5c | 66 50 22 0a 58 2e 53 48 |ibe_rng\|fP".X.SH|
|00001bc0| 20 44 45 53 43 52 49 50 | 54 49 4f 4e 0a 58 2e 4c | DESCRIP|TION.X.L|
|00001bd0| 50 0a 58 2e 49 20 6d 72 | 61 6e 64 6f 6d 28 6d 29 |P.X.I mr|andom(m)|
|00001be0| 0a 67 65 6e 65 72 61 74 | 65 73 20 72 61 6e 64 6f |.generat|es rando|
|00001bf0| 6d 20 69 6e 74 65 67 65 | 72 73 20 69 6e 20 74 68 |m intege|rs in th|
|00001c00| 65 20 72 61 6e 67 65 20 | 30 20 74 6f 20 6d 2d 31 |e range |0 to m-1|
|00001c10| 2c 20 75 73 69 6e 67 20 | 61 20 63 61 6c 6c 20 74 |, using |a call t|
|00001c20| 6f 20 74 68 65 0a 58 34 | 2e 33 62 73 64 20 72 61 |o the.X4|.3bsd ra|
|00001c30| 6e 64 6f 6d 28 29 20 66 | 75 6e 63 74 69 6f 6e 2e |ndom() f|unction.|
|00001c40| 0a 54 68 69 73 20 69 73 | 20 61 20 6e 6f 6e 2d 6c |.This is| a non-l|
|00001c50| 69 6e 65 61 72 20 61 64 | 64 69 74 69 76 65 20 66 |inear ad|ditive f|
|00001c60| 65 65 64 62 61 63 6b 20 | 72 61 6e 64 6f 6d 20 6e |eedback |random n|
|00001c70| 75 6d 62 65 72 20 67 65 | 6e 65 72 61 74 6f 72 2e |umber ge|nerator.|
|00001c80| 0a 54 68 65 20 6d 61 69 | 6e 20 61 64 76 61 6e 74 |.The mai|n advant|
|00001c90| 61 67 65 20 6f 66 20 6d | 72 61 6e 64 6f 6d 28 6d |age of m|random(m|
|00001ca0| 29 20 6f 76 65 72 20 72 | 61 6e 64 6f 6d 28 29 20 |) over r|andom() |
|00001cb0| 69 73 20 74 68 61 74 20 | 79 6f 75 20 63 61 6e 20 |is that |you can |
|00001cc0| 73 61 76 65 20 74 68 65 | 0a 63 6f 6d 70 6c 65 74 |save the|.complet|
|00001cd0| 65 20 73 74 61 74 65 20 | 6f 66 20 74 68 65 20 72 |e state |of the r|
|00001ce0| 61 6e 64 6f 6d 20 6e 75 | 6d 62 65 72 20 67 65 6e |andom nu|mber gen|
|00001cf0| 65 72 61 74 6f 72 20 74 | 6f 20 61 20 64 69 73 6b |erator t|o a disk|
|00001d00| 20 66 69 6c 65 2c 0a 66 | 6f 72 20 6c 61 74 65 72 | file,.f|or later|
|00001d10| 20 63 6f 6e 74 69 6e 75 | 61 74 69 6f 6e 20 6f 66 | continu|ation of|
|00001d20| 20 74 68 65 20 73 61 6d | 65 20 70 73 65 75 64 6f | the sam|e pseudo|
|00001d30| 72 61 6e 64 6f 6d 20 73 | 65 71 75 65 6e 63 65 2e |random s|equence.|
|00001d40| 0a 54 68 65 20 70 65 72 | 69 6f 64 20 6f 66 20 6d |.The per|iod of m|
|00001d50| 72 61 6e 64 6f 6d 28 6d | 29 27 73 20 70 73 65 75 |random(m|)'s pseu|
|00001d60| 64 6f 72 61 6e 64 6f 6d | 20 6f 75 74 70 75 74 20 |dorandom| output |
|00001d70| 69 73 20 74 68 75 73 20 | 67 75 61 72 61 6e 74 65 |is thus |guarante|
|00001d80| 65 64 20 74 6f 20 62 65 | 20 6c 6f 6e 67 2e 0a 49 |ed to be| long..I|
|00001d90| 6e 20 63 6f 6e 74 72 61 | 73 74 2c 20 72 61 6e 64 |n contra|st, rand|
|00001da0| 6f 6d 28 29 27 73 20 70 | 65 72 69 6f 64 20 63 61 |om()'s p|eriod ca|
|00001db0| 6e 20 62 65 20 71 75 69 | 74 65 20 73 68 6f 72 74 |n be qui|te short|
|00001dc0| 20 69 66 20 79 6f 75 20 | 72 65 70 65 61 74 65 64 | if you |repeated|
|00001dd0| 6c 79 0a 73 61 76 65 20 | 61 6e 64 20 72 65 73 74 |ly.save |and rest|
|00001de0| 6f 72 65 20 69 74 73 20 | 73 74 61 74 65 20 75 73 |ore its |state us|
|00001df0| 69 6e 67 20 73 65 74 73 | 74 61 74 65 28 29 2c 20 |ing sets|tate(), |
|00001e00| 62 65 63 61 75 73 65 20 | 73 6f 6d 65 20 6f 66 20 |because |some of |
|00001e10| 72 61 6e 64 6f 6d 28 29 | 27 73 0a 73 74 61 74 65 |random()|'s.state|
|00001e20| 20 69 73 20 70 72 69 76 | 61 74 65 2e 0a 58 2e 4c | is priv|ate..X.L|
|00001e30| 50 0a 54 6f 20 75 73 65 | 20 6d 72 61 6e 64 6f 6d |P.To use| mrandom|
|00001e40| 28 29 2c 20 79 6f 75 20 | 6d 75 73 74 20 66 69 72 |(), you |must fir|
|00001e50| 73 74 20 69 6e 69 74 69 | 61 6c 69 7a 65 20 74 68 |st initi|alize th|
|00001e60| 65 20 72 61 6e 64 6f 6d | 20 6e 75 6d 62 65 72 20 |e random| number |
|00001e70| 67 65 6e 65 72 61 74 6f | 72 2e 0a 54 68 65 20 65 |generato|r..The e|
|00001e80| 61 73 69 65 73 74 20 77 | 61 79 20 74 6f 20 64 6f |asiest w|ay to do|
|00001e90| 20 74 68 69 73 20 69 73 | 20 74 6f 20 6d 61 6b 65 | this is| to make|
|00001ea0| 20 61 20 63 61 6c 6c 20 | 74 6f 20 0a 58 2e 49 20 | a call |to .X.I |
|00001eb0| 69 6e 69 74 5f 72 6e 67 | 28 73 65 65 64 2c 20 66 |init_rng|(seed, f|
|00001ec0| 69 6c 65 6e 61 6d 65 29 | 2e 0a 49 66 20 61 6c 6c |ilename)|..If all|
|00001ed0| 20 67 6f 65 73 20 77 65 | 6c 6c 2c 20 74 68 69 73 | goes we|ll, this|
|00001ee0| 20 63 61 6c 6c 20 77 69 | 6c 6c 20 72 65 74 75 72 | call wi|ll retur|
|00001ef0| 6e 20 74 68 65 20 76 61 | 6c 75 65 20 31 2c 0a 69 |n the va|lue 1,.i|
|00001f00| 6e 64 69 63 61 74 69 6e | 67 20 74 68 61 74 20 61 |ndicatin|g that a|
|00001f10| 20 66 69 6c 65 20 68 61 | 73 20 62 65 65 6e 20 63 | file ha|s been c|
|00001f20| 72 65 61 74 65 64 0a 64 | 65 73 63 72 69 62 69 6e |reated.d|escribin|
|00001f30| 67 20 74 68 65 20 69 6e | 69 74 69 61 6c 20 73 74 |g the in|itial st|
|00001f40| 61 74 65 20 6f 66 20 79 | 6f 75 72 20 67 65 6e 65 |ate of y|our gene|
|00001f50| 72 61 74 6f 72 2e 0a 48 | 65 72 65 61 66 74 65 72 |rator..H|ereafter|
|00001f60| 2c 20 74 68 69 73 20 66 | 69 6c 65 20 77 69 6c 6c |, this f|ile will|
|00001f70| 20 62 65 20 63 61 6c 6c | 65 64 20 61 6e 20 52 4e | be call|ed an RN|
|00001f80| 47 20 73 74 61 74 65 20 | 66 69 6c 65 2e 0a 58 2e |G state |file..X.|
|00001f90| 4c 50 0a 58 2e 49 20 69 | 6e 69 74 5f 72 6e 67 0a |LP.X.I i|nit_rng.|
|00001fa0| 77 69 6c 6c 20 70 65 72 | 66 6f 72 6d 20 73 6f 6d |will per|form som|
|00001fb0| 65 20 65 72 72 6f 72 20 | 63 68 65 63 6b 73 20 6f |e error |checks o|
|00001fc0| 6e 20 74 68 65 20 52 4e | 47 20 73 74 61 74 65 20 |n the RN|G state |
|00001fd0| 66 69 6c 65 20 61 66 74 | 65 72 20 69 74 20 69 73 |file aft|er it is|
|00001fe0| 20 77 72 69 74 74 65 6e | 2c 0a 72 65 74 75 72 6e | written|,.return|
|00001ff0| 69 6e 67 20 74 68 65 20 | 76 61 6c 75 65 20 30 20 |ing the |value 0 |
|00002000| 69 66 20 61 20 70 72 6f | 62 6c 65 6d 20 69 73 20 |if a pro|blem is |
|00002010| 64 65 74 65 63 74 65 64 | 2e 0a 58 2e 4c 50 0a 41 |detected|..X.LP.A|
|00002020| 66 74 65 72 20 61 6e 0a | 58 2e 49 20 69 6e 69 74 |fter an.|X.I init|
|00002030| 5f 72 6e 67 28 73 65 65 | 64 2c 20 66 69 6c 65 6e |_rng(see|d, filen|
|00002040| 61 6d 65 29 0a 63 61 6c | 6c 2c 20 74 68 65 20 72 |ame).cal|l, the r|
|00002050| 61 6e 64 6f 6d 20 6e 75 | 6d 62 65 72 20 67 65 6e |andom nu|mber gen|
|00002060| 65 72 61 74 6f 72 20 69 | 73 20 69 6e 20 74 68 65 |erator i|s in the|
|00002070| 20 73 61 6d 65 20 73 74 | 61 74 65 20 61 73 20 69 | same st|ate as i|
|00002080| 74 20 77 6f 75 6c 64 0a | 62 65 20 69 66 20 79 6f |t would.|be if yo|
|00002090| 75 20 68 61 64 20 64 69 | 72 65 63 74 6c 79 20 63 |u had di|rectly c|
|000020a0| 61 6c 6c 65 64 0a 58 2e | 49 20 73 72 61 6e 64 6f |alled.X.|I srando|
|000020b0| 6d 28 73 65 65 64 29 0a | 6f 72 0a 58 2e 49 20 69 |m(seed).|or.X.I i|
|000020c0| 6e 69 74 73 74 61 74 65 | 28 73 65 65 64 2c 20 73 |nitstate|(seed, s|
|000020d0| 74 61 74 65 2c 20 31 32 | 38 29 0a 6f 6e 20 61 20 |tate, 12|8).on a |
|000020e0| 60 60 66 72 65 73 68 27 | 27 20 63 6f 70 79 20 6f |``fresh'|' copy o|
|000020f0| 66 20 74 68 65 20 72 61 | 6e 64 6f 6d 28 29 20 63 |f the ra|ndom() c|
|00002100| 6f 64 65 2e 0a 58 2e 4c | 50 0a 57 61 72 6e 69 6e |ode..X.L|P.Warnin|
|00002110| 67 3a 20 64 6f 20 6e 6f | 74 20 77 72 69 74 65 20 |g: do no|t write |
|00002120| 79 6f 75 72 20 6f 77 6e | 20 63 61 6c 6c 73 20 74 |your own| calls t|
|00002130| 6f 0a 58 2e 49 20 73 72 | 61 6e 64 6f 6d 28 29 2c |o.X.I sr|andom(),|
|00002140| 20 69 6e 69 74 73 74 61 | 74 65 28 29 2c 20 72 61 | initsta|te(), ra|
|00002150| 6e 64 6f 6d 28 29 2c 0a | 6f 72 0a 58 2e 49 20 73 |ndom(),.|or.X.I s|
|00002160| 65 74 73 74 61 74 65 28 | 29 0a 69 66 20 79 6f 75 |etstate(|).if you|
|00002170| 20 61 72 65 20 75 73 69 | 6e 67 20 74 68 65 20 6d | are usi|ng the m|
|00002180| 72 61 6e 64 6f 6d 20 70 | 61 63 6b 61 67 65 2e 0a |random p|ackage..|
|00002190| 49 66 20 79 6f 75 20 64 | 6f 20 73 6f 2c 20 74 68 |If you d|o so, th|
|000021a0| 65 20 6c 6f 6e 67 2d 70 | 65 72 69 6f 64 20 61 64 |e long-p|eriod ad|
|000021b0| 76 61 6e 74 61 67 65 73 | 20 6f 66 20 6d 72 61 6e |vantages| of mran|
|000021c0| 64 6f 6d 20 77 69 6c 6c | 20 62 65 20 6c 6f 73 74 |dom will| be lost|
|000021d0| 2c 0a 61 6e 64 20 61 20 | 6c 61 74 65 72 20 63 61 |,.and a |later ca|
|000021e0| 6c 6c 20 74 6f 20 73 61 | 76 65 5f 72 6e 67 20 6f |ll to sa|ve_rng o|
|000021f0| 72 20 72 65 73 74 6f 72 | 65 5f 72 6e 67 20 6d 61 |r restor|e_rng ma|
|00002200| 79 20 66 61 69 6c 2e 0a | 58 2e 4c 50 0a 49 74 20 |y fail..|X.LP.It |
|00002210| 69 73 20 67 6f 6f 64 20 | 65 78 70 65 72 69 6d 65 |is good |experime|
|00002220| 6e 74 61 6c 20 70 72 61 | 63 74 69 63 65 20 74 6f |ntal pra|ctice to|
|00002230| 20 70 72 65 73 65 72 76 | 65 20 63 6f 70 69 65 73 | preserv|e copies|
|00002240| 20 6f 66 0a 79 6f 75 72 | 20 52 4e 47 20 73 74 61 | of.your| RNG sta|
|00002250| 74 65 20 66 69 6c 65 73 | 2c 20 69 6e 20 63 61 73 |te files|, in cas|
|00002260| 65 20 79 6f 75 20 65 76 | 65 72 20 77 61 6e 74 20 |e you ev|er want |
|00002270| 74 6f 20 72 65 70 72 6f | 64 75 63 65 20 61 20 72 |to repro|duce a r|
|00002280| 65 73 75 6c 74 2e 0a 54 | 68 65 20 73 74 61 74 65 |esult..T|he state|
|00002290| 20 66 69 6c 65 20 69 73 | 20 41 53 43 49 49 20 74 | file is| ASCII t|
|000022a0| 65 78 74 2c 20 73 6f 20 | 69 74 20 69 73 20 70 6f |ext, so |it is po|
|000022b0| 72 74 61 62 6c 65 20 61 | 63 72 6f 73 73 20 73 79 |rtable a|cross sy|
|000022c0| 73 74 65 6d 73 2e 0a 58 | 2e 4c 50 0a 41 6e 6f 74 |stems..X|.LP.Anot|
|000022d0| 68 65 72 20 67 6f 6f 64 | 20 65 78 70 65 72 69 6d |her good| experim|
|000022e0| 65 6e 74 61 6c 20 70 72 | 61 63 74 69 63 65 20 69 |ental pr|actice i|
|000022f0| 73 20 74 6f 20 60 60 73 | 74 61 6d 70 27 27 20 65 |s to ``s|tamp'' e|
|00002300| 61 63 68 20 70 72 69 6e | 74 6f 75 74 0a 77 69 74 |ach prin|tout.wit|
|00002310| 68 20 61 20 72 65 63 6f | 72 64 20 6f 66 20 74 68 |h a reco|rd of th|
|00002320| 65 20 69 6e 69 74 69 61 | 6c 20 52 4e 47 20 73 74 |e initia|l RNG st|
|00002330| 61 74 65 2e 0a 59 6f 75 | 20 63 61 6e 20 64 6f 20 |ate..You| can do |
|00002340| 74 68 69 73 20 62 79 20 | 69 6e 63 6c 75 64 69 6e |this by |includin|
|00002350| 67 20 61 20 63 6f 70 79 | 20 6f 66 20 74 68 65 20 |g a copy| of the |
|00002360| 52 4e 47 20 73 74 61 74 | 65 20 66 69 6c 65 2c 20 |RNG stat|e file, |
|00002370| 61 6c 74 68 6f 75 67 68 | 0a 74 68 69 73 20 69 73 |although|.this is|
|00002380| 20 61 20 64 6f 7a 65 6e | 20 6c 69 6e 65 73 20 6c | a dozen| lines l|
|00002390| 6f 6e 67 20 61 6e 64 20 | 61 20 66 65 77 20 68 75 |ong and |a few hu|
|000023a0| 6e 64 72 65 64 20 63 68 | 61 72 61 63 74 65 72 73 |ndred ch|aracters|
|000023b0| 2e 0a 41 20 6d 6f 72 65 | 20 63 6f 6e 76 65 6e 69 |..A more| conveni|
|000023c0| 65 6e 74 20 6d 65 74 68 | 6f 64 20 69 73 20 74 6f |ent meth|od is to|
|000023d0| 20 75 73 65 20 61 20 63 | 61 6c 6c 20 74 6f 0a 58 | use a c|all to.X|
|000023e0| 2e 49 20 64 65 73 63 72 | 69 62 65 5f 72 6e 67 28 |.I descr|ibe_rng(|
|000023f0| 72 6e 67 69 64 29 2e 0a | 54 68 69 73 20 70 75 74 |rngid)..|This put|
|00002400| 73 20 61 20 6f 6e 65 2d | 6c 69 6e 65 20 73 68 6f |s a one-|line sho|
|00002410| 72 74 2d 66 6f 72 6d 20 | 6f 66 20 74 68 65 20 63 |rt-form |of the c|
|00002420| 75 72 72 65 6e 74 20 52 | 4e 47 20 73 74 61 74 65 |urrent R|NG state|
|00002430| 20 69 6e 20 74 68 65 0a | 63 68 61 72 61 63 74 65 | in the.|characte|
|00002440| 72 20 73 74 72 69 6e 67 | 20 72 6e 67 69 64 2e 0a |r string| rngid..|
|00002450| 58 2e 4c 50 0a 58 2e 49 | 20 64 65 73 63 72 69 62 |X.LP.X.I| describ|
|00002460| 65 5f 72 6e 67 28 72 6e | 67 69 64 29 0a 72 65 74 |e_rng(rn|gid).ret|
|00002470| 75 72 6e 73 20 74 68 65 | 20 76 61 6c 75 65 20 6f |urns the| value o|
|00002480| 66 20 72 6e 67 69 64 2c | 20 66 6f 72 20 63 6f 6e |f rngid,| for con|
|00002490| 76 65 6e 69 65 6e 63 65 | 2e 0a 54 6f 20 70 72 69 |venience|..To pri|
|000024a0| 6e 74 20 74 68 69 73 20 | 73 68 6f 72 74 2d 66 6f |nt this |short-fo|
|000024b0| 72 6d 20 52 4e 47 20 64 | 65 73 63 72 69 70 74 6f |rm RNG d|escripto|
|000024c0| 72 2c 20 66 6f 72 20 65 | 78 61 6d 70 6c 65 2c 0a |r, for e|xample,.|
|000024d0| 79 6f 75 20 63 61 6e 20 | 65 78 65 63 75 74 65 20 |you can |execute |
|000024e0| 70 72 69 6e 74 66 28 64 | 65 73 63 72 69 62 65 5f |printf(d|escribe_|
|000024f0| 72 6e 67 28 72 6e 67 69 | 64 29 29 2e 0a 4e 6f 74 |rng(rngi|d))..Not|
|00002500| 65 3a 20 79 6f 75 20 6d | 75 73 74 20 64 65 63 6c |e: you m|ust decl|
|00002510| 61 72 65 20 73 74 6f 72 | 61 67 65 20 66 6f 72 20 |are stor|age for |
|00002520| 72 6e 67 69 64 20 69 6e | 20 79 6f 75 72 20 6f 77 |rngid in| your ow|
|00002530| 6e 20 70 72 6f 67 72 61 | 6d 20 77 69 74 68 0a 61 |n progra|m with.a|
|00002540| 20 64 65 63 6c 61 72 61 | 74 69 6f 6e 20 73 75 63 | declara|tion suc|
|00002550| 68 20 61 73 0a 58 2e 49 | 20 63 68 61 72 20 72 6e |h as.X.I| char rn|
|00002560| 67 69 64 5b 52 4e 47 49 | 44 53 54 52 4c 45 4e 5d |gid[RNGI|DSTRLEN]|
|00002570| 2e 0a 58 2e 49 20 52 4e | 47 49 44 53 54 52 4c 45 |..X.I RN|GIDSTRLE|
|00002580| 4e 0a 69 73 20 64 65 66 | 69 6e 65 64 20 77 69 74 |N.is def|ined wit|
|00002590| 68 20 74 68 65 20 76 61 | 6c 75 65 20 38 30 20 69 |h the va|lue 80 i|
|000025a0| 6e 20 74 68 65 20 63 75 | 72 72 65 6e 74 20 72 65 |n the cu|rrent re|
|000025b0| 6c 65 61 73 65 20 6f 66 | 20 6d 72 61 6e 64 6f 6d |lease of| mrandom|
|000025c0| 2e 0a 58 2e 4c 50 0a 54 | 68 65 20 73 68 6f 72 74 |..X.LP.T|he short|
|000025d0| 2d 66 6f 72 6d 20 64 65 | 73 63 72 69 70 74 69 6f |-form de|scriptio|
|000025e0| 6e 20 70 72 6f 76 69 64 | 65 64 20 62 79 0a 58 2e |n provid|ed by.X.|
|000025f0| 49 20 64 65 73 63 72 69 | 62 65 5f 72 6e 67 0a 63 |I descri|be_rng.c|
|00002600| 61 6e 20 62 65 20 75 73 | 65 64 2c 20 61 74 20 61 |an be us|ed, at a|
|00002610| 20 6c 61 74 65 72 20 64 | 61 74 65 2c 20 74 6f 20 | later d|ate, to |
|00002620| 72 65 63 6f 6e 73 74 72 | 75 63 74 20 74 68 65 20 |reconstr|uct the |
|00002630| 73 74 61 74 65 20 6f 66 | 20 74 68 65 20 52 4e 47 |state of| the RNG|
|00002640| 2e 20 0a 54 68 69 73 20 | 63 61 6e 20 62 65 20 61 |. .This |can be a|
|00002650| 20 73 6c 6f 77 20 70 72 | 6f 63 65 73 73 2c 20 73 | slow pr|ocess, s|
|00002660| 69 6e 63 65 20 69 74 20 | 69 6e 76 6f 6c 76 65 73 |ince it |involves|
|00002670| 20 73 65 65 64 69 6e 67 | 20 61 20 76 69 72 67 69 | seeding| a virgi|
|00002680| 6e 20 63 6f 70 79 0a 6f | 66 20 74 68 65 20 72 61 |n copy.o|f the ra|
|00002690| 6e 64 6f 6d 28 29 20 67 | 65 6e 65 72 61 74 6f 72 |ndom() g|enerator|
|000026a0| 2c 20 74 68 65 6e 20 63 | 61 6c 6c 69 6e 67 20 72 |, then c|alling r|
|000026b0| 61 6e 64 6f 6d 28 29 20 | 61 20 6e 75 6d 62 65 72 |andom() |a number|
|000026c0| 20 6f 66 20 74 69 6d 65 | 73 2e 0a 54 68 65 20 72 | of time|s..The r|
|000026d0| 65 6c 65 76 61 6e 74 20 | 63 61 6c 6c 20 69 6e 20 |elevant |call in |
|000026e0| 74 68 65 20 6d 72 61 6e | 64 6f 6d 20 70 61 63 6b |the mran|dom pack|
|000026f0| 61 67 65 20 69 73 0a 58 | 2e 49 20 72 65 63 6f 6e |age is.X|.I recon|
|00002700| 73 74 72 75 63 74 5f 72 | 6e 67 28 73 65 65 64 2c |struct_r|ng(seed,|
|00002710| 20 63 6f 75 6e 74 31 2c | 20 63 6f 75 6e 74 32 29 | count1,| count2)|
|00002720| 2c 0a 77 68 65 72 65 20 | 73 65 65 64 20 69 73 20 |,.where |seed is |
|00002730| 74 68 65 20 69 6e 69 74 | 69 61 6c 20 73 65 65 64 |the init|ial seed|
|00002740| 2c 20 63 6f 75 6e 74 31 | 20 69 73 20 74 68 65 20 |, count1| is the |
|00002750| 74 6f 74 61 6c 20 6e 75 | 6d 62 65 72 20 6f 66 20 |total nu|mber of |
|00002760| 63 61 6c 6c 73 20 74 6f | 20 0a 72 61 6e 64 6f 6d |calls to| .random|
|00002770| 28 29 20 73 69 6e 63 65 | 20 69 6e 69 74 69 61 6c |() since| initial|
|00002780| 69 7a 61 74 69 6f 6e 2c | 20 6d 6f 64 20 6f 6e 65 |ization,| mod one|
|00002790| 20 62 69 6c 6c 69 6f 6e | 2c 0a 61 6e 64 20 63 6f | billion|,.and co|
|000027a0| 75 6e 74 32 20 69 73 20 | 61 20 60 60 64 69 76 20 |unt2 is |a ``div |
|000027b0| 6f 6e 65 20 62 69 6c 6c | 69 6f 6e 27 27 20 63 6f |one bill|ion'' co|
|000027c0| 75 6e 74 65 72 2e 0a 58 | 2e 4c 50 0a 49 20 68 6f |unter..X|.LP.I ho|
|000027d0| 70 65 20 79 6f 75 20 6e | 65 76 65 72 20 68 61 76 |pe you n|ever hav|
|000027e0| 65 20 6f 63 63 61 73 69 | 6f 6e 20 74 6f 20 63 61 |e occasi|on to ca|
|000027f0| 6c 6c 0a 58 2e 49 20 72 | 65 63 6f 6e 73 74 72 75 |ll.X.I r|econstru|
|00002800| 63 74 5f 72 6e 67 0a 69 | 66 20 63 6f 75 6e 74 32 |ct_rng.i|f count2|
|00002810| 20 69 73 20 67 72 65 61 | 74 65 72 20 74 68 61 6e | is grea|ter than|
|00002820| 20 7a 65 72 6f 21 0a 54 | 68 69 73 20 69 73 20 6f | zero!.T|his is o|
|00002830| 6e 65 20 72 65 61 73 6f | 6e 20 74 6f 20 70 72 65 |ne reaso|n to pre|
|00002840| 73 65 72 76 65 20 6f 63 | 63 61 73 69 6f 6e 61 6c |serve oc|casional|
|00002850| 20 63 6f 70 69 65 73 20 | 6f 66 20 74 68 65 20 63 | copies |of the c|
|00002860| 6f 6d 70 6c 65 74 65 0a | 52 4e 47 20 73 74 61 74 |omplete.|RNG stat|
|00002870| 65 2c 20 61 73 20 72 65 | 63 6f 72 64 65 64 20 69 |e, as re|corded i|
|00002880| 6e 20 74 68 65 20 52 4e | 47 20 73 74 61 74 65 20 |n the RN|G state |
|00002890| 66 69 6c 65 2e 0a 49 66 | 20 79 6f 75 20 68 61 76 |file..If| you hav|
|000028a0| 65 20 61 20 73 74 61 74 | 65 20 66 69 6c 65 2c 20 |e a stat|e file, |
|000028b0| 74 68 65 6e 0a 58 2e 49 | 20 72 65 73 74 61 72 74 |then.X.I| restart|
|000028c0| 5f 72 6e 67 28 66 69 6c | 65 6e 61 6d 65 29 0a 77 |_rng(fil|ename).w|
|000028d0| 69 6c 6c 20 61 6c 77 61 | 79 73 20 67 69 76 65 20 |ill alwa|ys give |
|000028e0| 72 61 70 69 64 20 72 65 | 73 75 6c 74 73 2e 0a 49 |rapid re|sults..I|
|000028f0| 66 20 74 68 65 20 52 4e | 47 20 73 74 61 74 65 20 |f the RN|G state |
|00002900| 66 69 6c 65 20 69 73 20 | 69 6e 74 65 72 6e 61 6c |file is |internal|
|00002910| 6c 79 20 69 6e 63 6f 6e | 73 69 73 74 65 6e 74 2c |ly incon|sistent,|
|00002920| 0a 72 65 73 74 61 72 74 | 5f 72 6e 67 20 77 69 6c |.restart|_rng wil|
|00002930| 6c 20 72 65 74 75 72 6e | 20 30 2c 20 6f 74 68 65 |l return| 0, othe|
|00002940| 72 77 69 73 65 20 69 74 | 20 72 65 74 75 72 6e 73 |rwise it| returns|
|00002950| 20 31 2e 0a 58 2e 4c 50 | 0a 4a 75 73 74 20 62 65 | 1..X.LP|.Just be|
|00002960| 66 6f 72 65 20 65 78 69 | 74 69 6e 67 20 61 20 70 |fore exi|ting a p|
|00002970| 72 6f 67 72 61 6d 20 74 | 68 61 74 20 75 73 65 73 |rogram t|hat uses|
|00002980| 20 6d 72 61 6e 64 6f 6d | 2c 20 61 20 63 61 6c 6c | mrandom|, a call|
|00002990| 20 74 6f 0a 58 2e 49 20 | 73 61 76 65 5f 72 6e 67 | to.X.I |save_rng|
|000029a0| 28 66 69 6c 65 6e 61 6d | 65 29 0a 77 69 6c 6c 20 |(filenam|e).will |
|000029b0| 70 72 65 73 65 72 76 65 | 20 74 68 65 20 66 69 6e |preserve| the fin|
|000029c0| 61 6c 20 73 74 61 74 65 | 20 6f 66 20 74 68 65 20 |al state| of the |
|000029d0| 52 4e 47 20 6f 6e 20 64 | 69 73 6b 2e 0a 4e 6f 74 |RNG on d|isk..Not|
|000029e0| 65 3a 20 49 20 68 61 76 | 65 20 66 6f 75 6e 64 20 |e: I hav|e found |
|000029f0| 69 74 20 68 65 6c 70 66 | 75 6c 20 74 6f 20 6d 61 |it helpf|ul to ma|
|00002a00| 6b 65 20 61 0a 73 61 76 | 65 5f 72 6e 67 20 63 61 |ke a.sav|e_rng ca|
|00002a10| 6c 6c 20 6f 6e 6c 79 20 | 75 70 6f 6e 20 6e 6f 72 |ll only |upon nor|
|00002a20| 6d 61 6c 20 65 78 69 74 | 20 66 72 6f 6d 0a 6d 79 |mal exit| from.my|
|00002a30| 20 65 78 70 65 72 69 6d | 65 6e 74 61 6c 20 63 6f | experim|ental co|
|00002a40| 64 65 73 2e 20 20 49 6e | 20 63 61 73 65 20 6f 66 |des. In| case of|
|00002a50| 20 61 6e 20 65 72 72 6f | 72 20 65 78 69 74 2c 20 | an erro|r exit, |
|00002a60| 69 74 20 69 73 20 63 6f | 6e 76 65 6e 69 65 6e 74 |it is co|nvenient|
|00002a70| 0a 74 6f 20 6c 65 61 76 | 65 20 74 68 65 20 52 4e |.to leav|e the RN|
|00002a80| 47 20 73 74 61 74 65 20 | 66 69 6c 65 20 69 6e 20 |G state |file in |
|00002a90| 69 74 73 20 69 6e 69 74 | 69 61 6c 20 63 6f 6e 64 |its init|ial cond|
|00002aa0| 69 74 69 6f 6e 2e 0a 54 | 68 69 73 20 6d 61 6b 65 |ition..T|his make|
|00002ab0| 73 20 69 74 20 65 61 73 | 79 20 74 6f 20 72 65 74 |s it eas|y to ret|
|00002ac0| 72 79 20 74 68 65 20 65 | 78 70 65 72 69 6d 65 6e |ry the e|xperimen|
|00002ad0| 74 20 61 66 74 65 72 20 | 66 69 78 69 6e 67 20 74 |t after |fixing t|
|00002ae0| 68 65 20 62 75 67 2e 0a | 58 2e 53 48 20 41 55 54 |he bug..|X.SH AUT|
|00002af0| 48 4f 52 0a 43 6c 61 72 | 6b 20 54 68 6f 6d 62 6f |HOR.Clar|k Thombo|
|00002b00| 72 73 6f 6e 2c 20 63 74 | 68 6f 6d 62 6f 72 40 67 |rson, ct|hombor@g|
|00002b10| 77 2e 64 2e 75 6d 6e 2e | 65 64 75 0a 58 2e 53 48 |w.d.umn.|edu.X.SH|
|00002b20| 20 44 49 41 47 4e 4f 53 | 54 49 43 53 0a 49 66 20 | DIAGNOS|TICS.If |
|00002b30| 74 68 65 20 65 72 72 6f | 72 2d 63 68 65 63 6b 69 |the erro|r-checki|
|00002b40| 6e 67 20 63 6f 64 65 20 | 69 6e 0a 58 2e 49 20 69 |ng code |in.X.I i|
|00002b50| 6e 69 74 5f 72 6e 67 2c | 20 72 65 73 74 61 72 74 |nit_rng,| restart|
|00002b60| 5f 72 6e 67 2c 0a 61 6e | 64 0a 58 2e 49 20 73 61 |_rng,.an|d.X.I sa|
|00002b70| 76 65 5f 72 6e 67 0a 64 | 69 73 63 6f 76 65 72 73 |ve_rng.d|iscovers|
|00002b80| 20 61 20 70 72 6f 62 6c | 65 6d 2c 20 61 6e 20 65 | a probl|em, an e|
|00002b90| 72 72 6f 72 20 6d 65 73 | 73 61 67 65 20 69 73 20 |rror mes|sage is |
|00002ba0| 70 72 69 6e 74 65 64 20 | 6f 6e 20 74 68 65 20 73 |printed |on the s|
|00002bb0| 74 64 65 72 72 20 73 74 | 72 65 61 6d 2e 0a 41 6c |tderr st|ream..Al|
|00002bc0| 73 6f 2c 20 69 66 0a 58 | 2e 49 20 72 65 63 6f 6e |so, if.X|.I recon|
|00002bd0| 73 74 72 75 63 74 5f 72 | 6e 67 0a 69 73 20 63 61 |struct_r|ng.is ca|
|00002be0| 6c 6c 65 64 20 77 69 74 | 68 20 63 6f 75 6e 74 32 |lled wit|h count2|
|00002bf0| 20 3e 20 30 2c 20 61 20 | 77 61 72 6e 69 6e 67 20 | > 0, a |warning |
|00002c00| 6d 65 73 73 61 67 65 20 | 69 73 20 70 72 69 6e 74 |message |is print|
|00002c10| 65 64 20 6f 6e 20 73 74 | 64 65 72 72 2e 0a 58 2e |ed on st|derr..X.|
|00002c20| 4c 50 0a 41 20 64 65 6d | 6f 6e 73 74 72 61 74 69 |LP.A dem|onstrati|
|00002c30| 6f 6e 20 72 6f 75 74 69 | 6e 65 2c 20 6e 61 6d 65 |on routi|ne, name|
|00002c40| 64 0a 58 2e 49 20 6d 72 | 74 65 73 74 2e 63 2c 0a |d.X.I mr|test.c,.|
|00002c50| 69 73 20 69 6e 63 6c 75 | 64 65 64 20 77 69 74 68 |is inclu|ded with|
|00002c60| 20 74 68 69 73 20 73 6f | 66 74 77 61 72 65 20 64 | this so|ftware d|
|00002c70| 69 73 74 72 69 62 75 74 | 69 6f 6e 20 74 6f 20 68 |istribut|ion to h|
|00002c80| 65 6c 70 20 67 65 74 20 | 79 6f 75 20 73 74 61 72 |elp get |you star|
|00002c90| 74 65 64 20 77 69 74 68 | 20 74 68 65 0a 58 2e 49 |ted with| the.X.I|
|00002ca0| 20 6d 72 61 6e 64 6f 6d | 0a 70 61 63 6b 61 67 65 | mrandom|.package|
|00002cb0| 2e 0a 58 2e 53 48 20 22 | 53 45 45 20 41 4c 53 4f |..X.SH "|SEE ALSO|
|00002cc0| 22 0a 72 61 6e 64 6f 6d | 28 33 29 2c 20 72 61 6e |".random|(3), ran|
|00002cd0| 64 28 33 43 29 2c 20 64 | 72 61 6e 64 34 38 28 33 |d(3C), d|rand48(3|
|00002ce0| 29 0a 58 2e 53 48 20 42 | 55 47 53 0a 41 20 6c 69 |).X.SH B|UGS.A li|
|00002cf0| 74 74 6c 65 20 73 6c 6f | 77 65 72 20 74 68 61 6e |ttle slo|wer than|
|00002d00| 0a 58 2e 49 20 72 61 6e | 64 6f 6d 28 29 2e 0a 58 |.X.I ran|dom()..X|
|00002d10| 2e 4c 50 0a 41 73 20 66 | 61 72 20 61 73 20 49 20 |.LP.As f|ar as I |
|00002d20| 6b 6e 6f 77 2c 0a 69 74 | 20 69 73 20 61 20 73 75 |know,.it| is a su|
|00002d30| 62 6a 65 63 74 20 6f 66 | 20 63 75 72 72 65 6e 74 |bject of| current|
|00002d40| 20 72 65 73 65 61 72 63 | 68 20 74 6f 20 64 65 63 | researc|h to dec|
|00002d50| 69 64 65 20 69 66 20 74 | 68 65 20 70 73 65 75 64 |ide if t|he pseud|
|00002d60| 6f 72 61 6e 64 6f 6d 20 | 73 65 71 75 65 6e 63 65 |orandom |sequence|
|00002d70| 20 6f 66 0a 58 2e 49 20 | 6d 72 61 6e 64 6f 6d 28 | of.X.I |mrandom(|
|00002d80| 29 0a 69 73 20 73 75 70 | 65 72 69 6f 72 20 74 6f |).is sup|erior to|
|00002d90| 20 74 68 61 74 20 6f 66 | 20 61 20 68 69 67 68 2d | that of| a high-|
|00002da0| 70 72 65 63 69 73 69 6f | 6e 20 6d 75 6c 74 69 70 |precisio|n multip|
|00002db0| 6c 69 63 61 74 69 76 65 | 20 67 65 6e 65 72 61 74 |licative| generat|
|00002dc0| 6f 72 20 73 75 63 68 20 | 61 73 0a 58 2e 49 20 64 |or such |as.X.I d|
|00002dd0| 72 61 6e 64 34 38 28 29 | 2e 0a 41 20 6c 6f 77 2d |rand48()|..A low-|
|00002de0| 70 72 65 63 69 73 69 6f | 6e 20 6d 75 6c 74 69 70 |precisio|n multip|
|00002df0| 6c 69 63 61 74 69 76 65 | 20 67 65 6e 65 72 61 74 |licative| generat|
|00002e00| 6f 72 2c 20 73 75 63 68 | 20 61 73 0a 58 2e 49 20 |or, such| as.X.I |
|00002e10| 72 61 6e 64 28 33 43 29 | 2c 0a 77 69 6c 6c 20 63 |rand(3C)|,.will c|
|00002e20| 61 75 73 65 20 70 72 6f | 62 6c 65 6d 73 20 69 6e |ause pro|blems in|
|00002e30| 20 6d 61 6e 79 20 61 70 | 70 6c 69 63 61 74 69 6f | many ap|plicatio|
|00002e40| 6e 73 2c 20 73 69 6e 63 | 65 20 6e 6f 6e 2d 72 61 |ns, sinc|e non-ra|
|00002e50| 6e 64 6f 6d 20 62 65 68 | 61 76 69 6f 72 0a 69 73 |ndom beh|avior.is|
|00002e60| 20 6e 6f 74 69 63 65 61 | 62 6c 65 20 69 6e 20 74 | noticea|ble in t|
|00002e70| 68 65 20 6c 65 61 73 74 | 2d 73 69 67 6e 69 66 69 |he least|-signifi|
|00002e80| 63 61 6e 74 20 74 77 65 | 6e 74 79 20 62 69 74 73 |cant twe|nty bits|
|00002e90| 20 6f 66 20 69 74 73 20 | 6f 75 74 70 75 74 2e 0a | of its |output..|
|00002ea0| 58 2e 4c 50 0a 43 75 72 | 72 65 6e 74 6c 79 2c 20 |X.LP.Cur|rently, |
|00002eb0| 74 68 65 20 62 65 73 74 | 20 74 68 65 6f 72 65 74 |the best| theoret|
|00002ec0| 69 63 61 6c 20 67 75 61 | 72 61 6e 74 65 65 73 20 |ical gua|rantees |
|00002ed0| 66 6f 72 20 70 73 65 75 | 64 6f 72 61 6e 64 6f 6d |for pseu|dorandom|
|00002ee0| 6e 65 73 73 20 63 6f 6d | 65 20 66 72 6f 6d 20 74 |ness com|e from t|
|00002ef0| 68 65 0a 74 68 65 6f 72 | 79 20 6f 66 20 75 6e 69 |he.theor|y of uni|
|00002f00| 76 65 72 73 61 6c 20 68 | 61 73 68 20 66 75 6e 63 |versal h|ash func|
|00002f10| 74 69 6f 6e 73 2e 0a 54 | 68 65 20 69 64 65 61 20 |tions..T|he idea |
|00002f20| 69 73 20 74 6f 20 75 73 | 65 20 61 20 68 69 67 68 |is to us|e a high|
|00002f30| 2d 70 72 65 63 69 73 69 | 6f 6e 20 6d 75 6c 74 69 |-precisi|on multi|
|00002f40| 70 6c 69 63 61 74 69 76 | 65 20 67 65 6e 65 72 61 |plicativ|e genera|
|00002f50| 74 6f 72 20 77 69 74 68 | 0a 72 61 6e 64 6f 6d 20 |tor with|.random |
|00002f60| 63 6f 65 66 66 69 63 69 | 65 6e 74 73 2e 0a 54 68 |coeffici|ents..Th|
|00002f70| 75 73 20 6f 6e 65 20 6d | 69 67 68 74 20 63 6f 6e |us one m|ight con|
|00002f80| 73 69 64 65 72 20 75 73 | 69 6e 67 20 74 68 65 20 |sider us|ing the |
|00002f90| 6d 72 61 6e 64 6f 6d 20 | 70 61 63 6b 61 67 65 20 |mrandom |package |
|00002fa0| 74 6f 20 67 65 6e 65 72 | 61 74 65 20 72 61 6e 64 |to gener|ate rand|
|00002fb0| 6f 6d 0a 63 6f 65 66 66 | 69 63 69 65 6e 74 73 2c |om.coeff|icients,|
|00002fc0| 20 6d 6f 64 75 6c 6f 20 | 6c 61 72 67 65 20 70 72 | modulo |large pr|
|00002fd0| 69 6d 65 73 2c 20 66 6f | 72 20 74 68 65 20 64 72 |imes, fo|r the dr|
|00002fe0| 61 6e 64 34 38 20 70 73 | 65 75 64 6f 72 61 6e 64 |and48 ps|eudorand|
|00002ff0| 6f 6d 20 6e 75 6d 62 65 | 72 0a 67 65 6e 65 72 61 |om numbe|r.genera|
|00003000| 74 6f 72 2e 0a 58 2e 4c | 50 0a 42 79 20 65 78 61 |tor..X.L|P.By exa|
|00003010| 6d 69 6e 61 74 69 6f 6e | 20 6f 66 20 74 68 65 20 |mination| of the |
|00003020| 6f 62 6a 65 63 74 20 63 | 6f 64 65 20 66 6f 72 20 |object c|ode for |
|00003030| 72 61 6e 64 6f 6d 28 29 | 2c 20 49 20 64 65 64 75 |random()|, I dedu|
|00003040| 63 65 20 74 68 61 74 0a | 69 74 20 75 73 65 73 20 |ce that.|it uses |
|00003050| 74 68 65 20 66 6f 6c 6c | 6f 77 69 6e 67 20 61 6c |the foll|owing al|
|00003060| 67 6f 72 69 74 68 6d 20 | 69 6e 20 69 74 73 20 64 |gorithm |in its d|
|00003070| 65 66 61 75 6c 74 20 28 | 33 31 2d 77 6f 72 64 20 |efault (|31-word |
|00003080| 74 61 62 6c 65 29 0a 63 | 6f 6e 66 69 67 75 72 61 |table).c|onfigura|
|00003090| 74 69 6f 6e 2e 0a 58 0a | 58 2e 49 44 0a 6c 6f 6e |tion..X.|X.ID.lon|
|000030a0| 67 20 72 61 6e 64 6f 6d | 28 29 0a 58 7b 0a 58 20 |g random|().X{.X |
|000030b0| 20 20 73 74 61 74 69 63 | 20 69 6e 74 20 6a 3d 34 | static| int j=4|
|000030c0| 2c 20 6b 3d 31 3b 0a 58 | 20 20 20 6c 6f 6e 67 20 |, k=1;.X| long |
|000030d0| 72 3b 20 20 20 0a 58 20 | 20 20 72 6e 67 73 74 61 |r; .X | rngsta|
|000030e0| 74 65 5b 6a 5d 20 2b 3d | 20 72 6e 67 73 74 61 74 |te[j] +=| rngstat|
|000030f0| 65 5b 6b 5d 3b 0a 58 20 | 20 20 72 20 3d 20 28 72 |e[k];.X | r = (r|
|00003100| 6e 67 73 74 61 74 65 5b | 6a 5d 3e 3e 31 29 20 26 |ngstate[|j]>>1) &|
|00003110| 20 30 78 37 66 66 66 66 | 66 66 66 3b 0a 58 20 20 | 0x7ffff|fff;.X |
|00003120| 20 6a 2b 2b 3b 0a 58 20 | 20 20 69 66 20 28 6a 3e | j++;.X | if (j>|
|00003130| 33 31 29 20 6a 3d 31 3b | 0a 58 20 20 20 6b 2b 2b |31) j=1;|.X k++|
|00003140| 3b 0a 58 20 20 20 69 66 | 20 28 6b 3e 33 31 29 20 |;.X if| (k>31) |
|00003150| 6b 3d 31 3b 0a 58 20 20 | 20 72 65 74 75 72 6e 28 |k=1;.X | return(|
|00003160| 72 29 3b 0a 58 0a 58 7d | 0a 58 2e 44 45 0a 58 0a |r);.X.X}|.X.DE.X.|
|00003170| 54 68 65 20 69 6e 69 74 | 69 61 6c 20 76 61 6c 75 |The init|ial valu|
|00003180| 65 73 20 66 6f 72 20 72 | 6e 67 73 74 61 74 65 20 |es for r|ngstate |
|00003190| 61 72 65 20 6f 62 74 61 | 69 6e 65 64 20 66 72 6f |are obta|ined fro|
|000031a0| 6d 20 61 20 6c 69 6e 65 | 61 72 20 63 6f 6e 67 72 |m a line|ar congr|
|000031b0| 75 65 6e 74 69 61 6c 0a | 67 65 6e 65 72 61 74 6f |uential.|generato|
|000031c0| 72 2e 20 20 41 6e 79 20 | 64 65 66 65 63 74 73 20 |r. Any |defects |
|000031d0| 6f 66 20 74 68 69 73 20 | 73 63 68 65 6d 65 20 77 |of this |scheme w|
|000031e0| 69 6c 6c 20 62 65 20 69 | 6e 68 65 72 69 74 65 64 |ill be i|nherited|
|000031f0| 20 62 79 20 6d 72 61 6e | 64 6f 6d 2e 0a 45 4e 44 | by mran|dom..END|
|00003200| 5f 4f 46 5f 46 49 4c 45 | 0a 69 66 20 74 65 73 74 |_OF_FILE|.if test|
|00003210| 20 37 35 35 33 20 2d 6e | 65 20 60 77 63 20 2d 63 | 7553 -n|e `wc -c|
|00003220| 20 3c 27 6d 72 61 6e 64 | 6f 6d 2e 33 27 60 3b 20 | <'mrand|om.3'`; |
|00003230| 74 68 65 6e 0a 20 20 20 | 20 65 63 68 6f 20 73 68 |then. | echo sh|
|00003240| 61 72 3a 20 5c 22 27 6d | 72 61 6e 64 6f 6d 2e 33 |ar: \"'m|random.3|
|00003250| 27 5c 22 20 75 6e 70 61 | 63 6b 65 64 20 77 69 74 |'\" unpa|cked wit|
|00003260| 68 20 77 72 6f 6e 67 20 | 73 69 7a 65 21 0a 66 69 |h wrong |size!.fi|
|00003270| 0a 23 20 65 6e 64 20 6f | 66 20 27 6d 72 61 6e 64 |.# end o|f 'mrand|
|00003280| 6f 6d 2e 33 27 0a 66 69 | 0a 69 66 20 74 65 73 74 |om.3'.fi|.if test|
|00003290| 20 2d 66 20 27 6d 72 61 | 6e 64 6f 6d 2e 63 27 20 | -f 'mra|ndom.c' |
|000032a0| 2d 61 20 22 24 7b 31 7d | 22 20 21 3d 20 22 2d 63 |-a "${1}|" != "-c|
|000032b0| 22 20 3b 20 74 68 65 6e | 20 0a 20 20 65 63 68 6f |" ; then| . echo|
|000032c0| 20 73 68 61 72 3a 20 57 | 69 6c 6c 20 6e 6f 74 20 | shar: W|ill not |
|000032d0| 63 6c 6f 62 62 65 72 20 | 65 78 69 73 74 69 6e 67 |clobber |existing|
|000032e0| 20 66 69 6c 65 20 5c 22 | 27 6d 72 61 6e 64 6f 6d | file \"|'mrandom|
|000032f0| 2e 63 27 5c 22 0a 65 6c | 73 65 0a 65 63 68 6f 20 |.c'\".el|se.echo |
|00003300| 73 68 61 72 3a 20 45 78 | 74 72 61 63 74 69 6e 67 |shar: Ex|tracting|
|00003310| 20 5c 22 27 6d 72 61 6e | 64 6f 6d 2e 63 27 5c 22 | \"'mran|dom.c'\"|
|00003320| 20 5c 28 31 30 35 36 39 | 20 63 68 61 72 61 63 74 | \(10569| charact|
|00003330| 65 72 73 5c 29 0a 73 65 | 64 20 22 73 2f 5e 58 2f |ers\).se|d "s/^X/|
|00003340| 2f 22 20 3e 27 6d 72 61 | 6e 64 6f 6d 2e 63 27 20 |/" >'mra|ndom.c' |
|00003350| 3c 3c 27 45 4e 44 5f 4f | 46 5f 46 49 4c 45 27 0a |<<'END_O|F_FILE'.|
|00003360| 58 2f 2a 0a 58 20 2a 09 | 09 6d 72 61 6e 64 6f 6d |X/*.X *.|.mrandom|
|00003370| 2e 63 0a 58 20 2a 0a 58 | 20 2a 09 57 72 61 70 70 |.c.X *.X| *.Wrapp|
|00003380| 65 72 20 66 6f 72 20 72 | 61 6e 64 6f 6d 28 29 2c |er for r|andom(),|
|00003390| 20 61 6c 6c 6f 77 69 6e | 67 20 73 61 66 65 20 72 | allowin|g safe r|
|000033a0| 65 73 74 61 72 74 2e 0a | 58 20 2a 0a 58 20 2a 09 |estart..|X *.X *.|
|000033b0| 4f 72 69 67 69 6e 61 6c | 20 49 6d 70 6c 65 6d 65 |Original| Impleme|
|000033c0| 6e 74 61 74 69 6f 6e 3a | 0a 58 20 2a 09 09 43 6c |ntation:|.X *..Cl|
|000033d0| 61 72 6b 20 54 68 6f 6d | 62 6f 72 73 6f 6e 2c 20 |ark Thom|borson, |
|000033e0| 53 65 70 74 65 6d 62 65 | 72 20 31 39 39 31 0a 58 |Septembe|r 1991.X|
|000033f0| 20 2a 0a 58 20 2a 09 54 | 68 69 73 20 6d 61 74 65 | *.X *.T|his mate|
|00003400| 72 69 61 6c 20 69 73 20 | 62 61 73 65 64 20 75 70 |rial is |based up|
|00003410| 6f 6e 20 77 6f 72 6b 20 | 73 75 70 70 6f 72 74 65 |on work |supporte|
|00003420| 64 20 62 79 20 74 68 65 | 20 4e 61 74 69 6f 6e 61 |d by the| Nationa|
|00003430| 6c 0a 58 20 2a 09 53 63 | 69 65 6e 63 65 20 46 6f |l.X *.Sc|ience Fo|
|00003440| 75 6e 64 61 74 69 6f 6e | 20 75 6e 64 65 72 20 67 |undation| under g|
|00003450| 72 61 6e 74 20 6e 75 6d | 62 65 72 20 4d 49 50 2d |rant num|ber MIP-|
|00003460| 39 30 32 33 32 33 38 2e | 20 20 54 68 65 0a 58 20 |9023238.| The.X |
|00003470| 2a 09 47 6f 76 65 72 6e | 6d 65 6e 74 20 68 61 73 |*.Govern|ment has|
|00003480| 20 63 65 72 74 61 69 6e | 20 72 69 67 68 74 73 20 | certain| rights |
|00003490| 69 6e 20 74 68 69 73 20 | 6d 61 74 65 72 69 61 6c |in this |material|
|000034a0| 2e 0a 58 20 2a 0a 58 20 | 2a 09 41 6e 79 20 6f 70 |..X *.X |*.Any op|
|000034b0| 69 6e 69 6f 6e 73 2c 20 | 66 69 6e 64 69 6e 67 73 |inions, |findings|
|000034c0| 2c 20 61 6e 64 20 63 6f | 6e 63 6c 75 73 69 6f 6e |, and co|nclusion|
|000034d0| 73 20 6f 72 20 72 65 63 | 6f 6d 6d 65 6e 64 61 74 |s or rec|ommendat|
|000034e0| 69 6f 6e 73 0a 58 20 2a | 09 65 78 70 72 65 73 73 |ions.X *|.express|
|000034f0| 65 64 20 69 6e 20 74 68 | 69 73 20 6d 61 74 65 72 |ed in th|is mater|
|00003500| 69 61 6c 20 61 72 65 20 | 74 68 6f 73 65 20 6f 66 |ial are |those of|
|00003510| 20 74 68 65 20 61 75 74 | 68 6f 72 20 61 6e 64 20 | the aut|hor and |
|00003520| 64 6f 0a 58 20 2a 09 6e | 6f 74 20 6e 65 63 65 73 |do.X *.n|ot neces|
|00003530| 73 61 72 69 6c 79 20 72 | 65 66 6c 65 63 74 20 74 |sarily r|eflect t|
|00003540| 68 65 20 76 69 65 77 20 | 6f 66 20 74 68 65 20 4e |he view |of the N|
|00003550| 61 74 69 6f 6e 61 6c 20 | 53 63 69 65 6e 63 65 0a |ational |Science.|
|00003560| 58 20 2a 09 46 6f 75 6e | 64 61 74 69 6f 6e 2e 0a |X *.Foun|dation..|
|00003570| 58 20 2a 0a 58 20 2a 09 | 54 68 69 73 20 63 6f 64 |X *.X *.|This cod|
|00003580| 65 20 69 73 20 6e 65 69 | 74 68 65 72 20 63 6f 70 |e is nei|ther cop|
|00003590| 79 72 69 67 68 74 65 64 | 20 6e 6f 72 20 70 61 74 |yrighted| nor pat|
|000035a0| 65 6e 74 65 64 2e 0a 58 | 20 2a 2f 0a 58 0a 58 23 |ented..X| */.X.X#|
|000035b0| 69 6e 63 6c 75 64 65 20 | 3c 76 61 6c 75 65 73 2e |include |<values.|
|000035c0| 68 3e 20 2f 2a 20 77 65 | 20 6e 65 65 64 20 4d 41 |h> /* we| need MA|
|000035d0| 58 4c 4f 4e 47 20 2a 2f | 0a 58 23 69 6e 63 6c 75 |XLONG */|.X#inclu|
|000035e0| 64 65 20 3c 73 74 64 69 | 6f 2e 68 3e 20 20 2f 2a |de <stdi|o.h> /*|
|000035f0| 20 77 65 20 6e 65 65 64 | 20 46 49 4c 45 20 2a 2f | we need| FILE */|
|00003600| 0a 58 23 69 6e 63 6c 75 | 64 65 20 22 6d 72 61 6e |.X#inclu|de "mran|
|00003610| 64 6f 6d 2e 68 22 0a 58 | 0a 58 23 64 65 66 69 6e |dom.h".X|.X#defin|
|00003620| 65 20 52 4e 47 53 54 41 | 54 45 4c 45 4e 47 54 48 |e RNGSTA|TELENGTH|
|00003630| 09 33 32 20 2f 2a 20 6c | 65 67 61 6c 20 76 61 6c |.32 /* l|egal val|
|00003640| 75 65 73 20 61 72 65 20 | 32 2c 20 38 2c 20 31 36 |ues are |2, 8, 16|
|00003650| 2c 20 33 32 2c 20 36 34 | 20 2a 2f 0a 58 23 64 65 |, 32, 64| */.X#de|
|00003660| 66 69 6e 65 20 52 4e 47 | 53 54 41 54 45 30 09 33 |fine RNG|STATE0.3|
|00003670| 20 20 2f 2a 20 72 6e 67 | 73 74 61 74 65 5b 30 5d | /* rng|state[0]|
|00003680| 20 66 6f 72 20 74 61 62 | 6c 65 20 6c 65 6e 67 74 | for tab|le lengt|
|00003690| 68 20 33 32 20 2a 2f 0a | 58 23 64 65 66 69 6e 65 |h 32 */.|X#define|
|000036a0| 20 42 49 4c 4c 49 4f 4e | 09 31 30 30 30 30 30 30 | BILLION|.1000000|
|000036b0| 30 30 30 20 2f 2a 20 63 | 6f 6e 76 65 6e 69 65 6e |000 /* c|onvenien|
|000036c0| 74 20 6d 6f 64 75 6c 75 | 73 20 66 6f 72 20 61 20 |t modulu|s for a |
|000036d0| 33 32 2d 62 69 74 20 63 | 6f 75 6e 74 65 72 20 2a |32-bit c|ounter *|
|000036e0| 2f 0a 58 0a 58 2f 2a 20 | 44 61 74 61 20 69 6e 20 |/.X.X/* |Data in |
|000036f0| 6f 75 72 20 52 4e 47 20 | 73 74 61 74 65 66 69 6c |our RNG |statefil|
|00003700| 65 20 2a 2f 0a 6c 6f 6e | 67 09 52 4e 47 73 65 65 |e */.lon|g.RNGsee|
|00003710| 64 3b 20 20 20 20 2f 2a | 20 74 68 65 20 73 65 65 |d; /*| the see|
|00003720| 64 20 6f 72 69 67 69 6e | 61 6c 6c 79 20 75 73 65 |d origin|ally use|
|00003730| 64 20 74 6f 20 69 6e 69 | 74 69 61 6c 69 7a 65 20 |d to ini|tialize |
|00003740| 72 6e 67 73 74 61 74 65 | 20 2a 2f 0a 6c 6f 6e 67 |rngstate| */.long|
|00003750| 09 52 4e 47 63 6f 75 6e | 74 31 3b 20 20 2f 2a 20 |.RNGcoun|t1; /* |
|00003760| 6d 6f 64 2d 42 49 4c 4c | 49 4f 4e 20 63 6f 75 6e |mod-BILL|ION coun|
|00003770| 74 65 72 20 6f 66 20 72 | 61 6e 64 6f 6d 28 29 20 |ter of r|andom() |
|00003780| 63 61 6c 6c 73 20 2a 2f | 0a 6c 6f 6e 67 09 52 4e |calls */|.long.RN|
|00003790| 47 63 6f 75 6e 74 32 3b | 20 20 2f 2a 20 64 69 76 |Gcount2;| /* div|
|000037a0| 2d 42 49 4c 4c 49 4f 4e | 20 63 6f 75 6e 74 65 72 |-BILLION| counter|
|000037b0| 20 2a 2f 0a 6c 6f 6e 67 | 09 72 6e 67 73 74 61 74 | */.long|.rngstat|
|000037c0| 65 5b 52 4e 47 53 54 41 | 54 45 4c 45 4e 47 54 48 |e[RNGSTA|TELENGTH|
|000037d0| 5d 3b 20 2f 2a 20 61 6e | 20 61 72 72 61 79 20 70 |]; /* an| array p|
|000037e0| 61 73 73 65 64 20 74 6f | 20 72 61 6e 64 6f 6d 28 |assed to| random(|
|000037f0| 29 20 2a 2f 0a 6c 6f 6e | 67 09 52 4e 47 6e 65 78 |) */.lon|g.RNGnex|
|00003800| 74 76 61 6c 3b 20 2f 2a | 20 72 61 6e 64 6f 6d 28 |tval; /*| random(|
|00003810| 29 27 73 20 6e 65 78 74 | 20 6f 75 74 70 75 74 20 |)'s next| output |
|00003820| 2a 2f 0a 58 0a 58 2f 2a | 20 46 6f 72 6d 61 74 20 |*/.X.X/*| Format |
|00003830| 6f 66 20 6f 75 72 20 52 | 4e 47 20 73 74 61 74 65 |of our R|NG state|
|00003840| 66 69 6c 65 20 2a 2f 0a | 58 23 64 65 66 69 6e 65 |file */.|X#define|
|00003850| 20 52 4e 47 66 69 6c 65 | 4c 49 4e 45 31 09 22 49 | RNGfile|LINE1."I|
|00003860| 6e 69 74 69 61 6c 20 73 | 65 65 64 20 3d 20 25 64 |nitial s|eed = %d|
|00003870| 5c 6e 22 0a 58 23 64 65 | 66 69 6e 65 20 52 4e 47 |\n".X#de|fine RNG|
|00003880| 66 69 6c 65 4c 49 4e 45 | 32 09 5c 0a 58 09 22 4e |fileLINE|2.\.X."N|
|00003890| 75 6d 62 65 72 20 6f 66 | 20 6d 72 61 6e 64 6f 6d |umber of| mrandom|
|000038a0| 28 29 20 63 61 6c 6c 73 | 20 61 66 74 65 72 20 73 |() calls| after s|
|000038b0| 65 65 64 69 6e 67 20 3d | 20 25 6c 64 20 62 69 6c |eeding =| %ld bil|
|000038c0| 6c 69 6f 6e 20 2b 20 25 | 6c 64 5c 6e 22 0a 58 23 |lion + %|ld\n".X#|
|000038d0| 64 65 66 69 6e 65 20 52 | 4e 47 66 69 6c 65 4c 49 |define R|NGfileLI|
|000038e0| 4e 45 33 09 22 52 4e 47 | 20 73 74 61 74 65 20 74 |NE3."RNG| state t|
|000038f0| 61 62 6c 65 20 3d 5c 6e | 22 0a 58 23 64 65 66 69 |able =\n|".X#defi|
|00003900| 6e 65 20 52 4e 47 66 69 | 6c 65 4c 49 4e 45 6e 09 |ne RNGfi|leLINEn.|
|00003910| 22 20 20 20 25 30 38 6c | 78 20 25 30 38 6c 78 20 |" %08l|x %08lx |
|00003920| 25 30 38 6c 78 20 25 30 | 38 6c 78 5c 6e 22 0a 58 |%08lx %0|8lx\n".X|
|00003930| 23 64 65 66 69 6e 65 20 | 52 4e 47 66 69 6c 65 4c |#define |RNGfileL|
|00003940| 49 4e 45 31 32 09 22 4e | 65 78 74 20 76 61 6c 75 |INE12."N|ext valu|
|00003950| 65 20 69 6e 20 74 68 69 | 73 20 70 73 65 75 64 6f |e in thi|s pseudo|
|00003960| 72 61 6e 64 6f 6d 20 73 | 65 71 75 65 6e 63 65 20 |random s|equence |
|00003970| 3d 20 25 30 38 6c 78 5c | 6e 22 0a 58 0a 58 2f 2a |= %08lx\|n".X.X/*|
|00003980| 20 57 72 69 74 65 20 61 | 20 52 4e 47 20 73 74 61 | Write a| RNG sta|
|00003990| 74 65 20 69 64 65 6e 74 | 69 66 69 65 72 20 69 6e |te ident|ifier in|
|000039a0| 74 6f 20 74 68 65 20 75 | 73 65 72 2d 73 75 70 70 |to the u|ser-supp|
|000039b0| 6c 69 65 64 20 73 74 72 | 69 6e 67 20 72 6e 67 69 |lied str|ing rngi|
|000039c0| 64 2c 0a 58 20 2a 20 77 | 68 69 63 68 20 6d 75 73 |d,.X * w|hich mus|
|000039d0| 74 20 62 65 20 6f 66 20 | 6c 65 6e 67 74 68 20 61 |t be of |length a|
|000039e0| 74 20 6c 65 61 73 74 20 | 52 4e 47 49 44 53 54 52 |t least |RNGIDSTR|
|000039f0| 4c 45 4e 2e 20 20 49 66 | 20 74 68 65 20 75 73 65 |LEN. If| the use|
|00003a00| 72 20 68 61 73 20 6e 6f | 74 0a 58 20 2a 20 69 6e |r has no|t.X * in|
|00003a10| 69 74 69 61 6c 69 7a 65 | 64 20 74 68 65 20 72 6e |itialize|d the rn|
|00003a20| 67 20 77 69 74 68 20 69 | 6e 69 74 5f 72 6e 67 28 |g with i|nit_rng(|
|00003a30| 29 2c 20 72 65 73 74 61 | 72 74 5f 72 6e 67 28 29 |), resta|rt_rng()|
|00003a40| 2c 20 6f 72 20 72 65 63 | 6f 6e 73 74 72 75 63 74 |, or rec|onstruct|
|00003a50| 5f 72 6e 67 28 29 2c 0a | 58 20 2a 20 61 62 6f 72 |_rng(),.|X * abor|
|00003a60| 74 20 77 69 74 68 20 61 | 6e 20 65 72 72 6f 72 20 |t with a|n error |
|00003a70| 6d 65 73 73 61 67 65 20 | 74 6f 20 73 74 64 65 72 |message |to stder|
|00003a80| 72 2e 20 20 4f 74 68 65 | 72 77 69 73 65 20 72 65 |r. Othe|rwise re|
|00003a90| 74 75 72 6e 20 74 68 65 | 20 76 61 6c 75 65 20 6f |turn the| value o|
|00003aa0| 66 20 72 6e 67 69 64 2e | 0a 58 20 2a 2f 0a 65 78 |f rngid.|.X */.ex|
|00003ab0| 74 65 72 6e 20 63 68 61 | 72 20 2a 64 65 73 63 72 |tern cha|r *descr|
|00003ac0| 69 62 65 5f 72 6e 67 20 | 28 72 6e 67 69 64 29 0a |ibe_rng |(rngid).|
|00003ad0| 63 68 61 72 20 72 6e 67 | 69 64 5b 52 4e 47 49 44 |char rng|id[RNGID|
|00003ae0| 53 54 52 4c 45 4e 5d 3b | 0a 58 7b 0a 58 20 20 69 |STRLEN];|.X{.X i|
|00003af0| 66 20 28 72 6e 67 73 74 | 61 74 65 5b 30 5d 20 21 |f (rngst|ate[0] !|
|00003b00| 3d 20 52 4e 47 53 54 41 | 54 45 30 29 20 7b 0a 58 |= RNGSTA|TE0) {.X|
|00003b10| 20 20 20 20 66 70 72 69 | 6e 74 66 28 73 74 64 65 | fpri|ntf(stde|
|00003b20| 72 72 2c 20 22 52 4e 47 | 20 68 61 73 20 6e 6f 74 |rr, "RNG| has not|
|00003b30| 20 62 65 65 6e 20 69 6e | 69 74 69 61 6c 69 7a 65 | been in|itialize|
|00003b40| 64 21 5c 6e 22 29 3b 0a | 58 20 20 20 20 66 66 6c |d!\n");.|X ffl|
|00003b50| 75 73 68 28 73 74 64 65 | 72 72 29 3b 0a 58 20 20 |ush(stde|rr);.X |
|00003b60| 20 20 65 78 69 74 28 31 | 29 3b 0a 58 20 20 7d 0a | exit(1|);.X }.|
|00003b70| 58 20 20 73 70 72 69 6e | 74 66 28 72 6e 67 69 64 |X sprin|tf(rngid|
|00003b80| 2c 20 22 52 4e 47 20 73 | 74 61 74 65 20 69 64 65 |, "RNG s|tate ide|
|00003b90| 6e 74 69 66 69 65 72 20 | 69 73 20 28 25 6c 64 2c |ntifier |is (%ld,|
|00003ba0| 20 25 6c 64 2c 20 25 6c | 64 29 5c 6e 22 2c 0a 58 | %ld, %l|d)\n",.X|
|00003bb0| 09 09 20 52 4e 47 73 65 | 65 64 2c 20 52 4e 47 63 |.. RNGse|ed, RNGc|
|00003bc0| 6f 75 6e 74 31 2c 20 52 | 4e 47 63 6f 75 6e 74 32 |ount1, R|NGcount2|
|00003bd0| 29 3b 0a 58 20 20 72 65 | 74 75 72 6e 28 72 6e 67 |);.X re|turn(rng|
|00003be0| 69 64 29 3b 0a 58 7d 0a | 58 0a 58 2f 2a 20 43 72 |id);.X}.|X.X/* Cr|
|00003bf0| 65 61 74 65 20 61 20 72 | 61 6e 64 6f 6d 20 6e 75 |eate a r|andom nu|
|00003c00| 6d 62 65 72 20 73 74 61 | 74 65 66 69 6c 65 20 69 |mber sta|tefile i|
|00003c10| 6e 69 74 69 61 6c 69 7a | 65 64 20 77 69 74 68 20 |nitializ|ed with |
|00003c20| 74 68 65 20 67 69 76 65 | 6e 20 73 65 65 64 2e 0a |the give|n seed..|
|00003c30| 58 20 2a 20 52 65 74 75 | 72 6e 20 31 20 69 66 20 |X * Retu|rn 1 if |
|00003c40| 66 69 6c 65 20 69 73 20 | 73 75 63 63 65 73 73 66 |file is |successf|
|00003c50| 75 6c 6c 79 20 63 72 65 | 61 74 65 64 2c 20 30 20 |ully cre|ated, 0 |
|00003c60| 6f 74 68 65 72 77 69 73 | 65 2e 0a 58 20 2a 2f 0a |otherwis|e..X */.|
|00003c70| 65 78 74 65 72 6e 20 69 | 6e 74 20 69 6e 69 74 5f |extern i|nt init_|
|00003c80| 72 6e 67 20 28 73 65 65 | 64 2c 20 66 69 6c 65 6e |rng (see|d, filen|
|00003c90| 61 6d 65 29 0a 69 6e 74 | 20 73 65 65 64 3b 0a 63 |ame).int| seed;.c|
|00003ca0| 68 61 72 20 2a 66 69 6c | 65 6e 61 6d 65 3b 0a 58 |har *fil|ename;.X|
|00003cb0| 7b 0a 58 20 20 72 65 63 | 6f 6e 73 74 72 75 63 74 |{.X rec|onstruct|
|00003cc0| 5f 72 6e 67 28 73 65 65 | 64 2c 30 2c 30 29 3b 0a |_rng(see|d,0,0);.|
|00003cd0| 58 20 20 72 65 74 75 72 | 6e 28 73 61 76 65 5f 72 |X retur|n(save_r|
|00003ce0| 6e 67 28 66 69 6c 65 6e | 61 6d 65 29 29 3b 0a 58 |ng(filen|ame));.X|
|00003cf0| 7d 20 2f 2a 20 65 6e 64 | 20 69 6e 69 74 5f 72 6e |} /* end| init_rn|
|00003d00| 67 20 2a 2f 0a 58 0a 58 | 2f 2a 20 52 65 62 75 69 |g */.X.X|/* Rebui|
|00003d10| 6c 64 20 61 20 72 61 6e | 64 6f 6d 28 29 20 73 74 |ld a ran|dom() st|
|00003d20| 61 74 65 20 62 79 20 72 | 65 73 65 65 64 69 6e 67 |ate by r|eseeding|
|00003d30| 20 74 68 65 20 67 65 6e | 65 72 61 74 6f 72 2c 20 | the gen|erator, |
|00003d40| 74 68 65 6e 20 6d 61 6b | 69 6e 67 0a 58 20 2a 20 |then mak|ing.X * |
|00003d50| 28 63 6f 75 6e 74 32 2a | 31 65 39 20 2b 20 63 6f |(count2*|1e9 + co|
|00003d60| 75 6e 74 31 29 20 63 61 | 6c 6c 73 20 74 6f 20 6d |unt1) ca|lls to m|
|00003d70| 72 61 6e 64 6f 6d 28 29 | 2e 20 20 55 73 65 66 75 |random()|. Usefu|
|00003d80| 6c 20 66 6f 72 20 65 72 | 72 6f 72 2d 63 68 65 63 |l for er|ror-chec|
|00003d90| 6b 69 6e 67 0a 58 20 2a | 20 61 6e 64 20 65 72 72 |king.X *| and err|
|00003da0| 6f 72 2d 72 65 63 6f 76 | 65 72 79 20 72 6f 75 74 |or-recov|ery rout|
|00003db0| 69 6e 65 73 2c 20 61 6c | 74 68 6f 75 67 68 20 69 |ines, al|though i|
|00003dc0| 74 20 69 73 20 76 65 72 | 79 20 73 6c 6f 77 20 66 |t is ver|y slow f|
|00003dd0| 6f 72 20 6c 61 72 67 65 | 20 63 6f 75 6e 74 73 2e |or large| counts.|
|00003de0| 0a 58 20 2a 2f 0a 65 78 | 74 65 72 6e 20 76 6f 69 |.X */.ex|tern voi|
|00003df0| 64 20 72 65 63 6f 6e 73 | 74 72 75 63 74 5f 72 6e |d recons|truct_rn|
|00003e00| 67 20 28 73 65 65 64 2c | 20 63 6f 75 6e 74 31 2c |g (seed,| count1,|
|00003e10| 20 63 6f 75 6e 74 32 29 | 0a 6c 6f 6e 67 20 73 65 | count2)|.long se|
|00003e20| 65 64 2c 20 63 6f 75 6e | 74 31 2c 20 63 6f 75 6e |ed, coun|t1, coun|
|00003e30| 74 32 3b 0a 58 7b 0a 58 | 20 20 64 6f 75 62 6c 65 |t2;.X{.X| double|
|00003e40| 20 61 3b 0a 58 20 20 69 | 6e 69 74 73 74 61 74 65 | a;.X i|nitstate|
|00003e50| 28 73 65 65 64 2c 20 72 | 6e 67 73 74 61 74 65 2c |(seed, r|ngstate,|
|00003e60| 20 52 4e 47 53 54 41 54 | 45 4c 45 4e 47 54 48 2a | RNGSTAT|ELENGTH*|
|00003e70| 34 29 3b 0a 58 20 20 52 | 4e 47 73 65 65 64 20 3d |4);.X R|NGseed =|
|00003e80| 20 73 65 65 64 3b 20 2f | 2a 20 6b 65 65 70 20 61 | seed; /|* keep a|
|00003e90| 20 72 65 63 6f 72 64 20 | 6f 66 20 74 68 65 20 73 | record |of the s|
|00003ea0| 65 65 64 20 2a 2f 0a 58 | 20 20 52 4e 47 63 6f 75 |eed */.X| RNGcou|
|00003eb0| 6e 74 31 20 3d 20 30 3b | 20 20 2f 2a 20 6d 6f 64 |nt1 = 0;| /* mod|
|00003ec0| 2d 62 69 6c 6c 69 6f 6e | 20 63 6f 75 6e 74 65 72 |-billion| counter|
|00003ed0| 20 2a 2f 0a 58 20 20 52 | 4e 47 63 6f 75 6e 74 32 | */.X R|NGcount2|
|00003ee0| 20 3d 20 30 3b 20 20 2f | 2a 20 64 69 76 2d 62 69 | = 0; /|* div-bi|
|00003ef0| 6c 6c 69 6f 6e 20 63 6f | 75 6e 74 65 72 20 2a 2f |llion co|unter */|
|00003f00| 0a 58 20 20 2f 2a 20 77 | 61 74 63 68 20 6f 75 74 |.X /* w|atch out|
|00003f10| 20 66 6f 72 20 69 6e 66 | 69 6e 69 74 65 20 6c 6f | for inf|inite lo|
|00003f20| 6f 70 73 20 2a 2f 0a 58 | 20 20 69 66 20 28 63 6f |ops */.X| if (co|
|00003f30| 75 6e 74 31 20 3e 3d 20 | 30 20 26 26 20 63 6f 75 |unt1 >= |0 && cou|
|00003f40| 6e 74 31 20 3c 20 42 49 | 4c 4c 49 4f 4e 20 26 26 |nt1 < BI|LLION &&|
|00003f50| 20 63 6f 75 6e 74 32 20 | 3e 3d 20 30 29 20 7b 0a | count2 |>= 0) {.|
|00003f60| 58 20 20 20 20 69 66 20 | 28 63 6f 75 6e 74 32 20 |X if |(count2 |
|00003f70| 21 3d 20 30 29 20 7b 0a | 58 20 20 20 20 20 20 66 |!= 0) {.|X f|
|00003f80| 70 72 69 6e 74 66 28 73 | 74 64 65 72 72 2c 20 22 |printf(s|tderr, "|
|00003f90| 57 61 72 6e 69 6e 67 3a | 20 74 68 69 73 20 72 65 |Warning:| this re|
|00003fa0| 63 6f 6e 73 74 72 75 63 | 74 69 6f 6e 20 77 69 6c |construc|tion wil|
|00003fb0| 6c 20 74 61 6b 65 20 61 | 20 4c 4f 4e 47 20 74 69 |l take a| LONG ti|
|00003fc0| 6d 65 21 5c 6e 22 29 3b | 0a 58 20 20 20 20 20 20 |me!\n");|.X |
|00003fd0| 66 66 6c 75 73 68 28 73 | 74 64 65 72 72 29 3b 0a |fflush(s|tderr);.|
|00003fe0| 58 20 20 20 20 7d 0a 58 | 20 20 20 20 66 6f 72 20 |X }.X| for |
|00003ff0| 28 20 3b 20 28 52 4e 47 | 63 6f 75 6e 74 31 20 21 |( ; (RNG|count1 !|
|00004000| 3d 20 63 6f 75 6e 74 31 | 29 20 7c 7c 20 28 52 4e |= count1|) || (RN|
|00004010| 47 63 6f 75 6e 74 32 20 | 21 3d 20 63 6f 75 6e 74 |Gcount2 |!= count|
|00004020| 32 29 20 3b 20 29 20 7b | 0a 58 20 20 20 20 20 20 |2) ; ) {|.X |
|00004030| 61 20 3d 20 66 72 61 6e | 64 6f 6d 28 29 3b 0a 58 |a = fran|dom();.X|
|00004040| 20 20 20 20 7d 0a 58 20 | 20 7d 0a 58 7d 20 2f 2a | }.X | }.X} /*|
|00004050| 20 65 6e 64 20 72 65 63 | 6f 6e 73 74 72 75 63 74 | end rec|onstruct|
|00004060| 5f 72 6e 67 20 2a 2f 0a | 58 0a 58 2f 2a 20 52 65 |_rng */.|X.X/* Re|
|00004070| 74 75 72 6e 20 74 68 65 | 20 6e 65 78 74 20 72 61 |turn the| next ra|
|00004080| 6e 64 6f 6d 28 29 20 6f | 75 74 70 75 74 20 77 69 |ndom() o|utput wi|
|00004090| 74 68 6f 75 74 20 64 69 | 73 74 75 72 62 69 6e 67 |thout di|sturbing|
|000040a0| 20 74 68 65 20 52 4e 47 | 20 73 74 61 74 65 2e 0a | the RNG| state..|
|000040b0| 58 20 20 20 54 68 69 73 | 20 70 72 6f 63 65 64 75 |X This| procedu|
|000040c0| 72 65 20 77 69 6c 6c 20 | 6f 6e 6c 79 20 77 6f 72 |re will |only wor|
|000040d0| 6b 20 70 72 6f 70 65 72 | 6c 79 20 69 66 20 72 61 |k proper|ly if ra|
|000040e0| 6e 64 6f 6d 27 73 20 73 | 74 61 74 65 20 69 73 20 |ndom's s|tate is |
|000040f0| 69 6e 20 72 6e 67 73 74 | 61 74 65 5b 5d 2e 0a 58 |in rngst|ate[]..X|
|00004100| 20 2a 2f 0a 69 6e 74 20 | 6e 65 78 74 76 61 6c 28 | */.int |nextval(|
|00004110| 29 0a 58 7b 0a 58 20 20 | 6c 6f 6e 67 20 73 74 61 |).X{.X |long sta|
|00004120| 74 65 5b 52 4e 47 53 54 | 41 54 45 4c 45 4e 47 54 |te[RNGST|ATELENGT|
|00004130| 48 5d 3b 0a 58 20 20 6c | 6f 6e 67 20 69 2c 20 72 |H];.X l|ong i, r|
|00004140| 2c 20 72 65 74 76 61 6c | 3b 0a 58 20 20 66 6f 72 |, retval|;.X for|
|00004150| 20 28 69 3d 30 3b 20 69 | 3c 52 4e 47 53 54 41 54 | (i=0; i|<RNGSTAT|
|00004160| 45 4c 45 4e 47 54 48 3b | 20 69 2b 2b 29 20 7b 0a |ELENGTH;| i++) {.|
|00004170| 58 20 20 20 20 73 74 61 | 74 65 5b 69 5d 20 3d 20 |X sta|te[i] = |
|00004180| 72 6e 67 73 74 61 74 65 | 5b 69 5d 3b 0a 58 20 20 |rngstate|[i];.X |
|00004190| 7d 0a 58 20 20 72 65 74 | 76 61 6c 20 3d 20 72 61 |}.X ret|val = ra|
|000041a0| 6e 64 6f 6d 28 29 3b 20 | 2f 2a 20 6e 65 78 74 20 |ndom(); |/* next |
|000041b0| 76 61 6c 75 65 20 69 6e | 20 74 68 69 73 20 70 73 |value in| this ps|
|000041c0| 65 75 64 6f 72 61 6e 64 | 6f 6d 20 73 65 71 75 65 |eudorand|om seque|
|000041d0| 6e 63 65 20 2a 2f 0a 58 | 20 20 66 6f 72 20 28 69 |nce */.X| for (i|
|000041e0| 3d 31 3b 20 69 3c 52 4e | 47 53 54 41 54 45 4c 45 |=1; i<RN|GSTATELE|
|000041f0| 4e 47 54 48 2d 31 3b 20 | 69 2b 2b 29 20 7b 0a 58 |NGTH-1; |i++) {.X|
|00004200| 20 20 20 20 72 20 3d 20 | 72 61 6e 64 6f 6d 28 29 | r = |random()|
|00004210| 3b 20 2f 2a 20 74 68 65 | 73 65 20 63 61 6c 6c 73 |; /* the|se calls|
|00004220| 20 61 72 65 20 6e 65 63 | 65 73 73 61 72 79 20 74 | are nec|essary t|
|00004230| 6f 20 72 65 73 74 6f 72 | 65 20 72 61 6e 64 6f 6d |o restor|e random|
|00004240| 28 29 27 73 20 73 74 61 | 74 65 20 2a 2f 0a 58 20 |()'s sta|te */.X |
|00004250| 20 7d 0a 58 20 20 66 6f | 72 20 28 69 3d 30 3b 20 | }.X fo|r (i=0; |
|00004260| 69 3c 52 4e 47 53 54 41 | 54 45 4c 45 4e 47 54 48 |i<RNGSTA|TELENGTH|
|00004270| 3b 20 69 2b 2b 29 20 7b | 0a 58 20 20 20 20 72 6e |; i++) {|.X rn|
|00004280| 67 73 74 61 74 65 5b 69 | 5d 20 3d 20 73 74 61 74 |gstate[i|] = stat|
|00004290| 65 5b 69 5d 3b 0a 58 20 | 20 7d 0a 58 20 20 72 65 |e[i];.X | }.X re|
|000042a0| 74 75 72 6e 28 72 65 74 | 76 61 6c 29 3b 0a 58 7d |turn(ret|val);.X}|
|000042b0| 0a 58 0a 58 2f 2a 20 52 | 65 73 74 61 72 74 20 61 |.X.X/* R|estart a|
|000042c0| 20 67 65 6e 65 72 61 74 | 6f 72 20 66 72 6f 6d 20 | generat|or from |
|000042d0| 61 20 73 74 61 74 65 66 | 69 6c 65 2e 20 20 50 72 |a statef|ile. Pr|
|000042e0| 69 6e 74 20 61 20 6d 65 | 73 73 61 67 65 20 6f 6e |int a me|ssage on|
|000042f0| 20 73 74 64 65 72 72 0a | 58 20 2a 20 69 66 20 74 | stderr.|X * if t|
|00004300| 68 65 20 72 65 73 74 61 | 72 74 20 66 61 69 6c 65 |he resta|rt faile|
|00004310| 64 20 64 75 65 20 74 6f | 20 61 20 67 61 72 62 6c |d due to| a garbl|
|00004320| 65 64 20 6f 72 20 6e 6f | 6e 2d 65 78 69 73 74 65 |ed or no|n-existe|
|00004330| 6e 74 20 73 74 61 74 65 | 66 69 6c 65 2c 20 0a 58 |nt state|file, .X|
|00004340| 20 2a 20 61 6e 64 20 72 | 65 74 75 72 6e 20 30 2e | * and r|eturn 0.|
|00004350| 20 20 4f 74 68 65 72 77 | 69 73 65 20 72 65 74 75 | Otherw|ise retu|
|00004360| 72 6e 20 31 2e 0a 58 20 | 2a 2f 0a 65 78 74 65 72 |rn 1..X |*/.exter|
|00004370| 6e 20 69 6e 74 20 72 65 | 73 74 61 72 74 5f 72 6e |n int re|start_rn|
|00004380| 67 28 66 69 6c 65 6e 61 | 6d 65 29 0a 63 68 61 72 |g(filena|me).char|
|00004390| 20 2a 66 69 6c 65 6e 61 | 6d 65 3b 0a 58 7b 0a 58 | *filena|me;.X{.X|
|000043a0| 20 20 46 49 4c 45 20 2a | 66 70 3b 0a 58 20 20 6c | FILE *|fp;.X l|
|000043b0| 6f 6e 67 20 69 2c 20 6d | 2c 20 6e 65 77 73 74 61 |ong i, m|, newsta|
|000043c0| 74 65 5b 52 4e 47 53 54 | 41 54 45 4c 45 4e 47 54 |te[RNGST|ATELENGT|
|000043d0| 48 5d 2c 20 72 3b 20 2f | 2a 20 74 65 6d 70 73 20 |H], r; /|* temps |
|000043e0| 2a 2f 0a 58 20 20 69 6e | 74 20 65 72 72 66 6c 61 |*/.X in|t errfla|
|000043f0| 67 3b 20 2f 2a 20 69 6e | 69 74 69 61 6c 6c 79 20 |g; /* in|itially |
|00004400| 30 2c 20 62 65 63 6f 6d | 65 73 20 31 20 69 66 20 |0, becom|es 1 if |
|00004410| 61 20 70 72 6f 62 6c 65 | 6d 20 69 73 20 64 69 73 |a proble|m is dis|
|00004420| 63 6f 76 65 72 65 64 20 | 2a 2f 0a 58 0a 58 20 20 |covered |*/.X.X |
|00004430| 2f 2a 20 72 65 73 74 6f | 72 65 20 72 61 6e 64 6f |/* resto|re rando|
|00004440| 6d 28 29 27 73 20 69 6e | 74 65 72 6e 61 6c 20 76 |m()'s in|ternal v|
|00004450| 61 72 69 61 62 6c 65 73 | 20 74 6f 20 74 68 65 69 |ariables| to thei|
|00004460| 72 20 69 6e 69 74 69 61 | 6c 20 73 74 61 74 65 20 |r initia|l state |
|00004470| 2a 2f 0a 58 20 20 6d 20 | 3d 20 28 52 4e 47 63 6f |*/.X m |= (RNGco|
|00004480| 75 6e 74 31 25 28 52 4e | 47 53 54 41 54 45 4c 45 |unt1%(RN|GSTATELE|
|00004490| 4e 47 54 48 2d 31 29 29 | 20 2b 20 52 4e 47 63 6f |NGTH-1))| + RNGco|
|000044a0| 75 6e 74 32 2a 28 42 49 | 4c 4c 49 4f 4e 25 28 52 |unt2*(BI|LLION%(R|
|000044b0| 4e 47 53 54 41 54 45 4c | 45 4e 47 54 48 2d 31 29 |NGSTATEL|ENGTH-1)|
|000044c0| 29 3b 0a 58 20 20 66 6f | 72 20 28 20 3b 20 6d 25 |);.X fo|r ( ; m%|
|000044d0| 28 52 4e 47 53 54 41 54 | 45 4c 45 4e 47 54 48 2d |(RNGSTAT|ELENGTH-|
|000044e0| 31 29 20 21 3d 20 30 3b | 20 6d 2b 2b 29 20 7b 0a |1) != 0;| m++) {.|
|000044f0| 58 20 20 20 20 72 20 3d | 20 72 61 6e 64 6f 6d 28 |X r =| random(|
|00004500| 29 3b 0a 58 20 20 7d 0a | 58 0a 58 20 20 2f 2a 20 |);.X }.|X.X /* |
|00004510| 72 65 73 74 6f 72 65 20 | 63 6f 75 6e 74 65 72 20 |restore |counter |
|00004520| 76 61 6c 75 65 73 2c 20 | 72 65 74 72 69 65 76 65 |values, |retrieve|
|00004530| 20 6f 72 69 67 69 6e 61 | 6c 20 52 4e 47 20 73 65 | origina|l RNG se|
|00004540| 65 64 20 61 6e 64 20 63 | 75 72 72 65 6e 74 20 73 |ed and c|urrent s|
|00004550| 74 61 74 65 20 2a 2f 0a | 58 20 20 66 70 20 3d 20 |tate */.|X fp = |
|00004560| 66 6f 70 65 6e 28 66 69 | 6c 65 6e 61 6d 65 2c 20 |fopen(fi|lename, |
|00004570| 22 72 22 29 3b 0a 58 20 | 20 69 66 20 28 21 66 70 |"r");.X | if (!fp|
|00004580| 29 20 7b 0a 58 20 20 20 | 20 66 70 72 69 6e 74 66 |) {.X | fprintf|
|00004590| 28 73 74 64 65 72 72 2c | 20 22 54 68 65 72 65 20 |(stderr,| "There |
|000045a0| 69 73 20 6e 6f 20 52 4e | 47 20 73 74 61 74 65 66 |is no RN|G statef|
|000045b0| 69 6c 65 20 69 6e 20 74 | 68 69 73 20 64 69 72 65 |ile in t|his dire|
|000045c0| 63 74 6f 72 79 21 5c 6e | 22 29 3b 0a 58 20 20 20 |ctory!\n|");.X |
|000045d0| 20 66 66 6c 75 73 68 28 | 73 74 64 65 72 72 29 3b | fflush(|stderr);|
|000045e0| 0a 58 20 20 20 20 65 78 | 69 74 28 31 29 3b 0a 58 |.X ex|it(1);.X|
|000045f0| 20 20 7d 0a 58 20 20 66 | 73 63 61 6e 66 28 66 70 | }.X f|scanf(fp|
|00004600| 2c 20 52 4e 47 66 69 6c | 65 4c 49 4e 45 31 2c 20 |, RNGfil|eLINE1, |
|00004610| 26 52 4e 47 73 65 65 64 | 29 3b 0a 58 20 20 66 73 |&RNGseed|);.X fs|
|00004620| 63 61 6e 66 28 66 70 2c | 20 52 4e 47 66 69 6c 65 |canf(fp,| RNGfile|
|00004630| 4c 49 4e 45 32 2c 20 26 | 52 4e 47 63 6f 75 6e 74 |LINE2, &|RNGcount|
|00004640| 32 2c 20 26 52 4e 47 63 | 6f 75 6e 74 31 29 3b 0a |2, &RNGc|ount1);.|
|00004650| 58 20 20 66 73 63 61 6e | 66 28 66 70 2c 20 52 4e |X fscan|f(fp, RN|
|00004660| 47 66 69 6c 65 4c 49 4e | 45 33 29 3b 0a 58 20 20 |GfileLIN|E3);.X |
|00004670| 66 6f 72 20 28 69 3d 30 | 3b 20 69 3c 52 4e 47 53 |for (i=0|; i<RNGS|
|00004680| 54 41 54 45 4c 45 4e 47 | 54 48 3b 20 69 2b 2b 29 |TATELENG|TH; i++)|
|00004690| 20 7b 0a 58 20 20 20 20 | 66 73 63 61 6e 66 28 66 | {.X |fscanf(f|
|000046a0| 70 2c 20 22 25 6c 78 22 | 2c 20 26 6e 65 77 73 74 |p, "%lx"|, &newst|
|000046b0| 61 74 65 5b 69 5d 29 3b | 0a 58 20 20 7d 0a 58 20 |ate[i]);|.X }.X |
|000046c0| 20 66 73 63 61 6e 66 28 | 66 70 2c 20 22 5c 6e 22 | fscanf(|fp, "\n"|
|000046d0| 29 3b 0a 58 20 20 66 73 | 63 61 6e 66 28 66 70 2c |);.X fs|canf(fp,|
|000046e0| 20 52 4e 47 66 69 6c 65 | 4c 49 4e 45 31 32 2c 20 | RNGfile|LINE12, |
|000046f0| 26 52 4e 47 6e 65 78 74 | 76 61 6c 29 3b 0a 58 20 |&RNGnext|val);.X |
|00004700| 20 66 63 6c 6f 73 65 28 | 66 70 29 3b 0a 58 0a 58 | fclose(|fp);.X.X|
|00004710| 20 20 2f 2a 20 65 72 72 | 6f 72 20 63 68 65 63 6b | /* err|or check|
|00004720| 3a 20 74 68 65 20 66 69 | 72 73 74 20 77 6f 72 64 |: the fi|rst word|
|00004730| 20 6f 66 20 61 20 33 32 | 2d 77 6f 72 64 20 72 6e | of a 32|-word rn|
|00004740| 67 73 74 61 74 65 20 69 | 73 20 61 6c 77 61 79 73 |gstate i|s always|
|00004750| 20 33 20 2a 2f 0a 58 20 | 20 69 66 20 28 6e 65 77 | 3 */.X | if (new|
|00004760| 73 74 61 74 65 5b 30 5d | 20 21 3d 20 52 4e 47 53 |state[0]| != RNGS|
|00004770| 54 41 54 45 30 29 20 7b | 0a 58 20 20 20 20 65 72 |TATE0) {|.X er|
|00004780| 72 66 6c 61 67 20 3d 20 | 31 3b 0a 58 20 20 7d 20 |rflag = |1;.X } |
|00004790| 65 6c 73 65 20 7b 0a 58 | 20 20 20 20 65 72 72 66 |else {.X| errf|
|000047a0| 6c 61 67 20 3d 20 30 3b | 0a 58 20 20 7d 0a 58 0a |lag = 0;|.X }.X.|
|000047b0| 58 20 20 2f 2a 20 74 65 | 6c 6c 20 72 61 6e 64 6f |X /* te|ll rando|
|000047c0| 6d 28 29 20 77 65 20 68 | 61 76 65 20 61 20 33 32 |m() we h|ave a 32|
|000047d0| 2d 77 6f 72 64 20 72 6e | 67 73 74 61 74 65 20 2a |-word rn|gstate *|
|000047e0| 2f 0a 58 20 20 72 6e 67 | 73 74 61 74 65 5b 30 5d |/.X rng|state[0]|
|000047f0| 20 3d 20 52 4e 47 53 54 | 41 54 45 30 3b 0a 58 20 | = RNGST|ATE0;.X |
|00004800| 20 73 65 74 73 74 61 74 | 65 28 72 6e 67 73 74 61 | setstat|e(rngsta|
|00004810| 74 65 29 3b 0a 58 0a 58 | 20 20 2f 2a 20 49 66 20 |te);.X.X| /* If |
|00004820| 72 65 63 6f 6e 73 74 72 | 75 63 74 69 6f 6e 20 77 |reconstr|uction w|
|00004830| 69 6c 6c 20 62 65 20 72 | 61 70 69 64 2c 20 64 6f |ill be r|apid, do|
|00004840| 20 69 74 20 61 73 20 61 | 6e 20 61 64 64 69 74 69 | it as a|n additi|
|00004850| 6f 6e 61 6c 20 65 72 72 | 6f 72 20 63 68 65 63 6b |onal err|or check|
|00004860| 2e 20 2a 2f 20 0a 58 20 | 20 69 66 20 28 52 4e 47 |. */ .X | if (RNG|
|00004870| 63 6f 75 6e 74 31 20 3c | 20 35 30 20 26 26 20 52 |count1 <| 50 && R|
|00004880| 4e 47 63 6f 75 6e 74 32 | 20 3d 3d 20 30 29 20 7b |NGcount2| == 0) {|
|00004890| 0a 58 20 20 20 20 72 65 | 63 6f 6e 73 74 72 75 63 |.X re|construc|
|000048a0| 74 5f 72 6e 67 28 52 4e | 47 73 65 65 64 2c 20 52 |t_rng(RN|Gseed, R|
|000048b0| 4e 47 63 6f 75 6e 74 31 | 2c 20 52 4e 47 63 6f 75 |NGcount1|, RNGcou|
|000048c0| 6e 74 32 29 3b 0a 58 20 | 20 20 20 2f 2a 20 73 65 |nt2);.X | /* se|
|000048d0| 65 20 69 66 20 77 65 20 | 67 6f 74 20 74 6f 20 74 |e if we |got to t|
|000048e0| 68 65 20 73 61 6d 65 20 | 73 74 61 74 65 20 2a 2f |he same |state */|
|000048f0| 0a 58 20 20 20 20 66 6f | 72 20 28 69 3d 30 3b 20 |.X fo|r (i=0; |
|00004900| 69 3c 52 4e 47 53 54 41 | 54 45 4c 45 4e 47 54 48 |i<RNGSTA|TELENGTH|
|00004910| 3b 20 69 2b 2b 29 20 7b | 0a 58 20 20 20 20 20 20 |; i++) {|.X |
|00004920| 69 66 20 28 6e 65 77 73 | 74 61 74 65 5b 69 5d 20 |if (news|tate[i] |
|00004930| 21 3d 20 72 6e 67 73 74 | 61 74 65 5b 69 5d 29 20 |!= rngst|ate[i]) |
|00004940| 7b 0a 58 20 20 20 20 20 | 20 20 20 65 72 72 66 6c |{.X | errfl|
|00004950| 61 67 20 3d 20 31 3b 0a | 58 20 20 20 20 20 20 7d |ag = 1;.|X }|
|00004960| 0a 58 20 20 20 20 7d 0a | 58 20 20 7d 20 65 6c 73 |.X }.|X } els|
|00004970| 65 20 7b 0a 58 20 20 20 | 20 2f 2a 20 71 75 69 63 |e {.X | /* quic|
|00004980| 6b 6c 79 20 6d 6f 64 69 | 66 79 20 72 61 6e 64 6f |kly modi|fy rando|
|00004990| 6d 28 29 27 73 20 69 6e | 74 65 72 6e 61 6c 20 73 |m()'s in|ternal s|
|000049a0| 74 61 74 65 20 74 6f 20 | 6c 69 6e 65 20 75 70 20 |tate to |line up |
|000049b0| 77 69 74 68 20 52 4e 47 | 63 6f 75 6e 74 20 69 6e |with RNG|count in|
|000049c0| 66 6f 20 2a 2f 0a 58 20 | 20 20 20 6d 20 3d 20 28 |fo */.X | m = (|
|000049d0| 52 4e 47 63 6f 75 6e 74 | 31 25 28 52 4e 47 53 54 |RNGcount|1%(RNGST|
|000049e0| 41 54 45 4c 45 4e 47 54 | 48 2d 31 29 29 20 2b 20 |ATELENGT|H-1)) + |
|000049f0| 52 4e 47 63 6f 75 6e 74 | 32 2a 28 42 49 4c 4c 49 |RNGcount|2*(BILLI|
|00004a00| 4f 4e 25 28 52 4e 47 53 | 54 41 54 45 4c 45 4e 47 |ON%(RNGS|TATELENG|
|00004a10| 54 48 2d 31 29 29 3b 0a | 58 20 20 20 20 66 6f 72 |TH-1));.|X for|
|00004a20| 20 28 69 3d 30 3b 20 69 | 20 3c 20 6d 25 28 52 4e | (i=0; i| < m%(RN|
|00004a30| 47 53 54 41 54 45 4c 45 | 4e 47 54 48 2d 31 29 3b |GSTATELE|NGTH-1);|
|00004a40| 20 69 2b 2b 29 20 7b 0a | 58 20 20 20 20 20 20 72 | i++) {.|X r|
|00004a50| 20 3d 20 72 61 6e 64 6f | 6d 28 29 3b 0a 58 20 20 | = rando|m();.X |
|00004a60| 20 20 7d 0a 58 20 20 7d | 0a 58 0a 58 20 20 2f 2a | }.X }|.X.X /*|
|00004a70| 20 63 6f 70 79 20 69 6e | 20 74 68 65 20 6e 65 77 | copy in| the new|
|00004a80| 20 73 74 61 74 65 20 2a | 2f 0a 58 20 20 66 6f 72 | state *|/.X for|
|00004a90| 20 28 69 3d 30 3b 20 69 | 3c 52 4e 47 53 54 41 54 | (i=0; i|<RNGSTAT|
|00004aa0| 45 4c 45 4e 47 54 48 3b | 20 69 2b 2b 29 20 7b 0a |ELENGTH;| i++) {.|
|00004ab0| 58 20 20 20 20 72 6e 67 | 73 74 61 74 65 5b 69 5d |X rng|state[i]|
|00004ac0| 20 3d 20 6e 65 77 73 74 | 61 74 65 5b 69 5d 3b 0a | = newst|ate[i];.|
|00004ad0| 58 20 20 7d 0a 58 0a 58 | 20 20 2f 2a 20 43 68 65 |X }.X.X| /* Che|
|00004ae0| 63 6b 20 6e 65 78 74 76 | 61 6c 28 29 20 6f 70 65 |ck nextv|al() ope|
|00004af0| 72 61 74 69 6f 6e 2c 20 | 61 6e 64 20 76 65 72 69 |ration, |and veri|
|00004b00| 66 79 20 52 4e 47 6e 65 | 78 74 76 61 6c 20 2a 2f |fy RNGne|xtval */|
|00004b10| 0a 58 20 20 69 66 20 28 | 6e 65 78 74 76 61 6c 28 |.X if (|nextval(|
|00004b20| 29 20 21 3d 20 6e 65 78 | 74 76 61 6c 28 29 20 7c |) != nex|tval() ||
|00004b30| 7c 20 52 4e 47 6e 65 78 | 74 76 61 6c 20 21 3d 20 || RNGnex|tval != |
|00004b40| 6e 65 78 74 76 61 6c 28 | 29 29 20 7b 0a 58 20 20 |nextval(|)) {.X |
|00004b50| 20 20 65 72 72 66 6c 61 | 67 20 3d 20 31 3b 0a 58 | errfla|g = 1;.X|
|00004b60| 20 20 7d 0a 58 0a 58 20 | 20 69 66 20 28 65 72 72 | }.X.X | if (err|
|00004b70| 66 6c 61 67 29 20 7b 0a | 58 20 20 20 20 66 70 72 |flag) {.|X fpr|
|00004b80| 69 6e 74 66 28 73 74 64 | 65 72 72 2c 0a 58 09 22 |intf(std|err,.X."|
|00004b90| 57 61 72 6e 69 6e 67 3a | 20 52 4e 47 20 73 74 61 |Warning:| RNG sta|
|00004ba0| 74 65 66 69 6c 65 20 69 | 73 20 69 6e 63 6f 6e 73 |tefile i|s incons|
|00004bb0| 69 73 74 65 6e 74 2e 20 | 20 44 69 64 20 79 6f 75 |istent. | Did you|
|00004bc0| 20 65 64 69 74 20 69 74 | 3f 5c 6e 22 29 3b 0a 58 | edit it|?\n");.X|
|00004bd0| 20 20 20 20 66 70 72 69 | 6e 74 66 28 73 74 64 65 | fpri|ntf(stde|
|00004be0| 72 72 2c 0a 58 09 22 49 | 66 20 6e 6f 74 2c 20 63 |rr,.X."I|f not, c|
|00004bf0| 68 65 63 6b 20 79 6f 75 | 72 20 70 72 6f 67 72 61 |heck you|r progra|
|00004c00| 6d 20 74 6f 20 6d 61 6b | 65 20 73 75 72 65 20 79 |m to mak|e sure y|
|00004c10| 6f 75 3a 5c 6e 22 29 3b | 0a 58 20 20 20 20 66 70 |ou:\n");|.X fp|
|00004c20| 72 69 6e 74 66 28 73 74 | 64 65 72 72 2c 0a 58 09 |rintf(st|derr,.X.|
|00004c30| 22 20 20 20 31 2e 20 75 | 73 65 20 66 72 61 6e 64 |" 1. u|se frand|
|00004c40| 6f 6d 28 29 20 6f 72 20 | 6d 72 61 6e 64 6f 6d 28 |om() or |mrandom(|
|00004c50| 6d 29 2c 20 6e 6f 74 20 | 72 61 6e 64 6f 6d 28 29 |m), not |random()|
|00004c60| 3b 5c 6e 22 29 3b 0a 58 | 20 20 20 20 66 70 72 69 |;\n");.X| fpri|
|00004c70| 6e 74 66 28 73 74 64 65 | 72 72 2c 0a 58 09 22 20 |ntf(stde|rr,.X." |
|00004c80| 20 20 32 2e 20 75 73 65 | 20 69 6e 69 74 5f 72 6e | 2. use| init_rn|
|00004c90| 67 28 73 65 65 64 2c 20 | 66 69 6c 65 6e 61 6d 65 |g(seed, |filename|
|00004ca0| 29 2c 20 6e 6f 74 20 73 | 72 61 6e 64 6f 6d 28 73 |), not s|random(s|
|00004cb0| 65 65 64 29 3b 5c 6e 22 | 29 3b 0a 58 20 20 20 20 |eed);\n"|);.X |
|00004cc0| 66 70 72 69 6e 74 66 28 | 73 74 64 65 72 72 2c 0a |fprintf(|stderr,.|
|00004cd0| 58 09 22 20 20 20 33 2e | 20 75 73 65 20 72 65 73 |X." 3.| use res|
|00004ce0| 74 61 72 74 5f 72 6e 67 | 28 66 69 6c 65 6e 61 6d |tart_rng|(filenam|
|00004cf0| 65 29 2c 20 6e 6f 74 20 | 73 65 74 73 74 61 74 65 |e), not |setstate|
|00004d00| 28 73 74 61 74 65 29 3b | 20 61 6e 64 5c 6e 22 29 |(state);| and\n")|
|00004d10| 3b 0a 58 20 20 20 20 66 | 70 72 69 6e 74 66 28 73 |;.X f|printf(s|
|00004d20| 74 64 65 72 72 2c 0a 58 | 09 22 20 20 20 34 2e 20 |tderr,.X|." 4. |
|00004d30| 64 6f 6e 27 74 20 6f 76 | 65 72 77 72 69 74 65 20 |don't ov|erwrite |
|00004d40| 74 68 65 20 70 72 69 76 | 61 74 65 20 73 74 6f 72 |the priv|ate stor|
|00004d50| 61 67 65 20 6f 66 20 6d | 72 61 6e 64 6f 6d 2e 5c |age of m|random.\|
|00004d60| 6e 22 29 3b 0a 58 20 20 | 20 20 66 66 6c 75 73 68 |n");.X | fflush|
|00004d70| 28 73 74 64 65 72 72 29 | 3b 0a 58 20 20 20 20 72 |(stderr)|;.X r|
|00004d80| 65 74 75 72 6e 28 30 29 | 3b 0a 58 20 20 7d 20 65 |eturn(0)|;.X } e|
|00004d90| 6c 73 65 20 7b 0a 58 20 | 20 20 20 72 65 74 75 72 |lse {.X | retur|
|00004da0| 6e 28 31 29 3b 20 2f 2a | 20 65 76 65 72 79 74 68 |n(1); /*| everyth|
|00004db0| 69 6e 67 20 6c 6f 6f 6b | 73 20 6f 6b 20 2a 2f 0a |ing look|s ok */.|
|00004dc0| 58 20 20 7d 0a 58 7d 20 | 2f 2a 20 65 6e 64 20 72 |X }.X} |/* end r|
|00004dd0| 65 73 74 61 72 74 5f 72 | 6e 67 20 2a 2f 0a 58 0a |estart_r|ng */.X.|
|00004de0| 58 2f 2a 20 47 65 6e 65 | 72 61 74 65 20 61 20 75 |X/* Gene|rate a u|
|00004df0| 6e 69 66 6f 72 6d 6c 79 | 2d 64 69 73 74 72 69 62 |niformly|-distrib|
|00004e00| 75 74 65 64 20 6e 75 6d | 62 65 72 20 61 2c 20 30 |uted num|ber a, 0|
|00004e10| 2e 30 20 3c 3d 20 61 20 | 3c 20 31 2e 30 2c 20 75 |.0 <= a |< 1.0, u|
|00004e20| 73 69 6e 67 0a 58 20 2a | 20 74 68 65 20 34 2e 33 |sing.X *| the 4.3|
|00004e30| 62 73 64 20 61 64 64 69 | 74 69 76 65 20 63 6f 6e |bsd addi|tive con|
|00004e40| 67 72 75 65 6e 74 69 61 | 6c 20 67 65 6e 65 72 61 |gruentia|l genera|
|00004e50| 74 6f 72 20 72 61 6e 64 | 6f 6d 28 29 2e 0a 58 20 |tor rand|om()..X |
|00004e60| 2a 0a 58 20 2a 20 54 68 | 69 73 20 72 6f 75 74 69 |*.X * Th|is routi|
|00004e70| 6e 65 20 6b 65 65 70 73 | 20 74 72 61 63 6b 20 6f |ne keeps| track o|
|00004e80| 66 20 74 68 65 20 6e 75 | 6d 62 65 72 20 6f 66 20 |f the nu|mber of |
|00004e90| 63 61 6c 6c 73 20 74 6f | 20 72 61 6e 64 6f 6d 28 |calls to| random(|
|00004ea0| 29 2e 0a 58 20 2a 0a 58 | 20 2a 20 46 72 6f 6d 20 |)..X *.X| * From |
|00004eb0| 69 6e 73 70 65 63 74 69 | 6f 6e 20 6f 66 20 74 68 |inspecti|on of th|
|00004ec0| 65 20 6f 62 6a 65 63 74 | 20 63 6f 64 65 20 66 6f |e object| code fo|
|00004ed0| 72 20 72 61 6e 64 6f 6d | 28 29 20 69 6e 20 61 20 |r random|() in a |
|00004ee0| 53 75 6e 2d 33 20 72 65 | 6c 65 61 73 65 2c 0a 58 |Sun-3 re|lease,.X|
|00004ef0| 20 2a 20 49 20 64 65 64 | 75 63 65 20 74 68 65 20 | * I ded|uce the |
|00004f00| 66 6f 6c 6c 6f 77 69 6e | 67 2e 20 20 41 20 63 61 |followin|g. A ca|
|00004f10| 6c 6c 20 74 6f 20 69 6e | 69 74 73 74 61 74 65 28 |ll to in|itstate(|
|00004f20| 29 20 6f 72 20 73 65 74 | 73 74 61 74 65 28 29 0a |) or set|state().|
|00004f30| 58 20 2a 20 20 20 31 2e | 20 64 65 66 69 6e 65 73 |X * 1.| defines|
|00004f40| 20 74 68 65 20 6c 6f 63 | 61 74 69 6f 6e 20 6f 66 | the loc|ation of|
|00004f50| 20 74 68 65 20 73 74 61 | 74 65 20 61 72 72 61 79 | the sta|te array|
|00004f60| 20 28 72 6e 67 73 74 61 | 74 65 20 69 6e 20 74 68 | (rngsta|te in th|
|00004f70| 65 20 63 6f 64 65 20 62 | 65 6c 6f 77 29 3b 0a 58 |e code b|elow);.X|
|00004f80| 20 2a 20 20 20 32 2e 20 | 64 65 66 69 6e 65 73 20 | * 2. |defines |
|00004f90| 74 68 65 20 6c 65 6e 67 | 74 68 20 6f 66 20 74 68 |the leng|th of th|
|00004fa0| 65 20 73 74 61 74 65 20 | 61 72 72 61 79 20 28 33 |e state |array (3|
|00004fb0| 32 20 77 6f 72 64 73 20 | 69 6e 20 74 68 65 20 63 |2 words |in the c|
|00004fc0| 6f 64 65 20 62 65 6c 6f | 77 3b 0a 58 20 2a 09 6f |ode belo|w;.X *.o|
|00004fd0| 74 68 65 72 20 70 6f 73 | 73 69 62 69 6c 69 74 69 |ther pos|sibiliti|
|00004fe0| 65 73 20 61 72 65 20 32 | 2c 20 38 2c 20 31 36 2c |es are 2|, 8, 16,|
|00004ff0| 20 6f 72 20 36 34 20 77 | 6f 72 64 73 29 3b 0a 58 | or 64 w|ords);.X|
|00005000| 20 2a 20 20 20 33 2e 20 | 69 6e 69 74 69 61 6c 69 | * 3. |initiali|
|00005010| 7a 65 73 20 73 65 76 65 | 72 61 6c 20 73 74 61 74 |zes seve|ral stat|
|00005020| 69 63 20 76 61 72 69 61 | 62 6c 65 73 20 74 6f 20 |ic varia|bles to |
|00005030| 70 6f 69 6e 74 20 61 74 | 20 74 68 65 20 73 74 61 |point at| the sta|
|00005040| 74 65 20 61 72 72 61 79 | 0a 58 20 2a 09 28 74 68 |te array|.X *.(th|
|00005050| 65 20 69 6e 64 69 63 65 | 73 20 6a 20 61 6e 64 20 |e indice|s j and |
|00005060| 6b 20 69 6e 20 74 68 65 | 20 63 6f 64 65 20 62 65 |k in the| code be|
|00005070| 6c 6f 77 29 3b 0a 58 20 | 2a 20 20 20 34 2e 20 64 |low);.X |* 4. d|
|00005080| 65 66 69 6e 65 73 20 74 | 68 65 20 72 61 6e 64 6f |efines t|he rando|
|00005090| 6d 69 7a 61 74 69 6f 6e | 20 61 6c 67 6f 72 69 74 |mization| algorit|
|000050a0| 68 6d 20 28 61 20 6c 69 | 6e 65 61 72 20 63 6f 6e |hm (a li|near con|
|000050b0| 67 72 75 65 6e 74 69 61 | 6c 0a 58 20 2a 09 67 65 |gruentia|l.X *.ge|
|000050c0| 6e 65 72 61 74 6f 72 20 | 69 73 20 75 73 65 64 20 |nerator |is used |
|000050d0| 69 66 20 74 68 65 20 73 | 74 61 74 65 20 61 72 72 |if the s|tate arr|
|000050e0| 61 79 20 68 61 73 20 6c | 65 6e 67 74 68 20 32 29 |ay has l|ength 2)|
|000050f0| 2e 0a 58 20 2a 20 41 64 | 64 69 74 69 6f 6e 61 6c |..X * Ad|ditional|
|00005100| 6c 79 2c 20 69 6e 69 74 | 73 74 61 74 65 28 73 65 |ly, init|state(se|
|00005110| 65 64 29 20 66 69 6c 6c | 73 20 74 68 65 20 73 74 |ed) fill|s the st|
|00005120| 61 74 65 20 61 72 72 61 | 79 20 77 69 74 68 20 74 |ate arra|y with t|
|00005130| 68 65 20 6f 75 74 70 75 | 74 0a 58 20 2a 20 6f 66 |he outpu|t.X * of|
|00005140| 20 61 20 6c 69 6e 65 61 | 72 20 63 6f 6e 67 72 75 | a linea|r congru|
|00005150| 65 6e 74 69 61 6c 20 67 | 65 6e 65 72 61 74 6f 72 |ential g|enerator|
|00005160| 20 74 68 61 74 20 69 73 | 20 73 65 65 64 65 64 20 | that is| seeded |
|00005170| 77 69 74 68 20 74 68 65 | 20 67 69 76 65 6e 20 73 |with the| given s|
|00005180| 65 65 64 2e 0a 58 20 2a | 0a 58 20 2a 20 48 65 72 |eed..X *|.X * Her|
|00005190| 65 20 69 73 20 61 20 64 | 69 73 61 73 73 65 6d 62 |e is a d|isassemb|
|000051a0| 6c 65 64 20 61 6e 64 20 | 64 65 63 6f 6d 70 69 6c |led and |decompil|
|000051b0| 65 64 20 6c 69 73 74 69 | 6e 67 20 6f 66 20 72 61 |ed listi|ng of ra|
|000051c0| 6e 64 6f 6d 28 29 2c 20 | 61 73 0a 58 20 2a 20 69 |ndom(), |as.X * i|
|000051d0| 74 20 77 6f 75 6c 64 20 | 6f 70 65 72 61 74 65 20 |t would |operate |
|000051e0| 77 68 65 6e 20 69 6e 69 | 74 69 61 6c 69 7a 65 64 |when ini|tialized|
|000051f0| 20 77 69 74 68 20 6d 79 | 20 69 6e 69 74 5f 72 6e | with my| init_rn|
|00005200| 67 20 72 6f 75 74 69 6e | 65 3a 0a 58 20 2a 0a 58 |g routin|e:.X *.X|
|00005210| 20 2a 20 6c 6f 6e 67 20 | 72 61 6e 64 6f 6d 28 29 | * long |random()|
|00005220| 0a 58 20 2a 20 7b 0a 58 | 20 2a 20 20 20 73 74 61 |.X * {.X| * sta|
|00005230| 74 69 63 20 69 6e 74 20 | 6a 3d 34 2c 20 6b 3d 31 |tic int |j=4, k=1|
|00005240| 3b 0a 58 20 2a 20 20 20 | 6c 6f 6e 67 20 72 3b 20 |;.X * |long r; |
|00005250| 20 20 0a 58 20 2a 20 20 | 20 72 6e 67 73 74 61 74 | .X * | rngstat|
|00005260| 65 5b 6a 5d 20 2b 3d 20 | 72 6e 67 73 74 61 74 65 |e[j] += |rngstate|
|00005270| 5b 6b 5d 3b 0a 58 20 2a | 20 20 20 72 20 3d 20 28 |[k];.X *| r = (|
|00005280| 72 6e 67 73 74 61 74 65 | 5b 6a 5d 3e 3e 31 29 20 |rngstate|[j]>>1) |
|00005290| 26 20 30 78 37 66 66 66 | 66 66 66 66 3b 0a 58 20 |& 0x7fff|ffff;.X |
|000052a0| 2a 20 20 20 6a 2b 2b 3b | 0a 58 20 2a 20 20 20 69 |* j++;|.X * i|
|000052b0| 66 20 28 6a 3e 33 31 29 | 20 6a 3d 31 3b 0a 58 20 |f (j>31)| j=1;.X |
|000052c0| 2a 20 20 20 6b 2b 2b 3b | 0a 58 20 2a 20 20 20 69 |* k++;|.X * i|
|000052d0| 66 20 28 6b 3e 33 31 29 | 20 6b 3d 31 3b 0a 58 20 |f (k>31)| k=1;.X |
|000052e0| 2a 20 20 20 72 65 74 75 | 72 6e 28 72 29 3b 0a 58 |* retu|rn(r);.X|
|000052f0| 20 2a 20 7d 0a 58 20 2a | 0a 58 20 2a 20 4e 6f 74 | * }.X *|.X * Not|
|00005300| 65 20 74 68 61 74 20 6a | 20 61 6e 64 20 6b 20 72 |e that j| and k r|
|00005310| 65 74 75 72 6e 20 74 6f | 20 74 68 65 69 72 20 6f |eturn to| their o|
|00005320| 72 69 67 69 6e 61 6c 20 | 76 61 6c 75 65 73 20 61 |riginal |values a|
|00005330| 66 74 65 72 20 65 76 65 | 72 79 20 33 31 0a 58 20 |fter eve|ry 31.X |
|00005340| 2a 20 63 61 6c 6c 73 20 | 74 6f 20 72 61 6e 64 6f |* calls |to rando|
|00005350| 6d 28 29 2e 20 20 54 68 | 69 73 20 70 72 6f 70 65 |m(). Th|is prope|
|00005360| 72 74 79 20 61 6c 6c 6f | 77 73 20 6d 65 20 74 6f |rty allo|ws me to|
|00005370| 20 77 72 69 74 65 20 61 | 20 72 65 73 74 61 72 74 | write a| restart|
|00005380| 5f 72 6e 67 28 29 0a 58 | 20 2a 20 72 6f 75 74 69 |_rng().X| * routi|
|00005390| 6e 65 20 65 76 65 6e 20 | 74 68 6f 75 67 68 20 49 |ne even |though I|
|000053a0| 20 63 61 6e 27 74 20 72 | 65 61 64 20 74 68 65 20 | can't r|ead the |
|000053b0| 76 61 6c 75 65 73 20 6f | 66 20 6a 20 61 6e 64 20 |values o|f j and |
|000053c0| 6b 2e 20 0a 58 20 2a 0a | 58 20 2a 20 41 6c 73 6f |k. .X *.|X * Also|
|000053d0| 20 6e 6f 74 65 20 74 68 | 61 74 20 74 68 69 73 20 | note th|at this |
|000053e0| 69 73 20 61 20 76 65 72 | 79 20 70 6f 6f 72 20 52 |is a ver|y poor R|
|000053f0| 4e 47 20 61 6c 67 6f 72 | 69 74 68 6d 20 69 66 20 |NG algor|ithm if |
|00005400| 69 74 20 69 73 20 6f 6e | 6c 79 0a 58 20 2a 20 63 |it is on|ly.X * c|
|00005410| 61 6c 6c 65 64 20 6f 6e | 63 65 20 62 65 74 77 65 |alled on|ce betwe|
|00005420| 65 6e 20 73 75 63 63 65 | 73 73 69 76 65 20 73 65 |en succe|ssive se|
|00005430| 74 73 74 61 74 65 28 29 | 20 63 61 6c 6c 73 2e 20 |tstate()| calls. |
|00005440| 20 49 6e 20 74 68 69 73 | 20 70 61 74 68 6f 6c 6f | In this| patholo|
|00005450| 67 69 63 61 6c 0a 58 20 | 2a 20 63 61 73 65 2c 20 |gical.X |* case, |
|00005460| 65 61 63 68 20 6f 75 74 | 70 75 74 20 6f 66 20 72 |each out|put of r|
|00005470| 61 6e 64 6f 6d 28 29 20 | 77 69 6c 6c 20 64 69 66 |andom() |will dif|
|00005480| 66 65 72 20 66 72 6f 6d | 20 74 68 65 20 70 72 69 |fer from| the pri|
|00005490| 6f 72 20 72 61 6e 64 6f | 6d 28 29 20 6f 75 74 70 |or rando|m() outp|
|000054a0| 75 74 0a 58 20 2a 20 62 | 79 20 72 6e 67 73 74 61 |ut.X * b|y rngsta|
|000054b0| 74 65 5b 31 5d 2f 32 20 | 6f 72 20 72 6e 67 73 74 |te[1]/2 |or rngst|
|000054c0| 61 74 65 5b 31 5d 2f 32 | 2b 31 2c 20 6d 6f 64 20 |ate[1]/2|+1, mod |
|000054d0| 32 5e 33 31 2d 31 2e 20 | 20 45 76 65 6e 20 69 6e |2^31-1. | Even in|
|000054e0| 20 6e 6f 6e 2d 70 61 74 | 68 6f 6c 6f 67 69 63 61 | non-pat|hologica|
|000054f0| 6c 0a 58 20 2a 20 63 61 | 6c 6c 69 6e 67 20 73 65 |l.X * ca|lling se|
|00005500| 71 75 65 6e 63 65 73 20 | 74 68 65 20 6c 6f 6e 67 |quences |the long|
|00005510| 2d 70 65 72 69 6f 64 20 | 70 72 6f 70 65 72 74 79 |-period |property|
|00005520| 20 6f 66 20 61 6e 20 61 | 64 64 69 74 69 76 65 20 | of an a|dditive |
|00005530| 63 6f 6e 67 72 75 65 6e | 74 69 61 6c 0a 58 20 2a |congruen|tial.X *|
|00005540| 20 67 65 6e 65 72 61 74 | 6f 72 20 69 73 20 6f 6e | generat|or is on|
|00005550| 6c 79 20 67 75 61 72 61 | 6e 74 65 65 64 20 69 66 |ly guara|nteed if|
|00005560| 20 6a 20 61 6e 64 20 6b | 20 61 6c 77 61 79 73 20 | j and k| always |
|00005570| 6d 6f 76 65 20 74 68 72 | 6f 75 67 68 20 74 68 65 |move thr|ough the|
|00005580| 20 61 72 72 61 79 0a 58 | 20 2a 20 69 6e 20 74 68 | array.X| * in th|
|00005590| 65 20 6d 61 6e 6e 65 72 | 20 73 68 6f 77 6e 2e 20 |e manner| shown. |
|000055a0| 20 54 68 75 73 20 74 68 | 65 20 6e 65 65 64 20 66 | Thus th|e need f|
|000055b0| 6f 72 20 63 6f 75 6e 74 | 69 6e 67 20 72 61 6e 64 |or count|ing rand|
|000055c0| 6f 6d 28 29 20 63 61 6c | 6c 73 0a 58 20 2a 20 28 |om() cal|ls.X * (|
|000055d0| 6f 72 20 66 6f 72 20 77 | 72 69 74 69 6e 67 20 79 |or for w|riting y|
|000055e0| 6f 75 72 20 6f 77 6e 20 | 74 69 6d 65 2d 6f 70 74 |our own |time-opt|
|000055f0| 69 6d 69 7a 65 64 20 61 | 64 64 69 74 69 76 65 20 |imized a|dditive |
|00005600| 63 6f 6e 67 72 75 65 6e | 74 69 61 6c 20 67 65 6e |congruen|tial gen|
|00005610| 65 72 61 74 6f 72 29 2e | 0a 58 20 2a 0a 58 20 2a |erator).|.X *.X *|
|00005620| 20 46 69 6e 61 6c 6c 79 | 2c 20 6e 6f 74 65 20 74 | Finally|, note t|
|00005630| 68 61 74 20 69 6e 74 65 | 67 65 72 20 6f 76 65 72 |hat inte|ger over|
|00005640| 66 6c 6f 77 20 69 73 20 | 61 20 66 72 65 71 75 65 |flow is |a freque|
|00005650| 6e 74 20 6f 63 63 75 72 | 72 65 6e 63 65 20 69 6e |nt occur|rence in|
|00005660| 0a 58 20 2a 20 72 6e 67 | 73 74 61 74 65 5b 6b 5d |.X * rng|state[k]|
|00005670| 20 2b 3d 20 72 6e 67 73 | 74 61 74 65 5b 6a 5d 2e | += rngs|tate[j].|
|00005680| 20 20 54 68 75 73 20 72 | 61 6e 64 6f 6d 28 29 20 | Thus r|andom() |
|00005690| 63 6f 75 6c 64 20 63 6f | 6e 63 65 69 76 61 62 6c |could co|nceivabl|
|000056a0| 79 0a 58 20 2a 20 62 65 | 68 61 76 65 20 64 69 66 |y.X * be|have dif|
|000056b0| 66 65 72 65 6e 74 6c 79 | 20 6f 6e 20 64 69 66 66 |ferently| on diff|
|000056c0| 65 72 65 6e 74 20 6d 61 | 63 68 69 6e 65 73 2e 0a |erent ma|chines..|
|000056d0| 58 20 2a 2f 0a 65 78 74 | 65 72 6e 20 64 6f 75 62 |X */.ext|ern doub|
|000056e0| 6c 65 20 66 72 61 6e 64 | 6f 6d 20 28 29 0a 58 7b |le frand|om ().X{|
|000056f0| 0a 58 20 20 52 4e 47 63 | 6f 75 6e 74 31 2b 2b 3b |.X RNGc|ount1++;|
|00005700| 20 2f 2a 20 6d 6f 64 2d | 62 69 6c 6c 69 6f 6e 20 | /* mod-|billion |
|00005710| 63 6f 75 6e 74 65 72 20 | 2a 2f 0a 58 20 20 69 66 |counter |*/.X if|
|00005720| 20 28 52 4e 47 63 6f 75 | 6e 74 31 20 3d 3d 20 42 | (RNGcou|nt1 == B|
|00005730| 49 4c 4c 49 4f 4e 29 20 | 7b 0a 58 20 20 20 20 52 |ILLION) |{.X R|
|00005740| 4e 47 63 6f 75 6e 74 31 | 20 3d 20 30 3b 0a 58 20 |NGcount1| = 0;.X |
|00005750| 20 20 20 52 4e 47 63 6f | 75 6e 74 32 2b 2b 3b 20 | RNGco|unt2++; |
|00005760| 2f 2a 20 61 6e 20 6f 76 | 65 72 66 6c 6f 77 20 69 |/* an ov|erflow i|
|00005770| 73 20 75 6e 6c 69 6b 65 | 6c 79 20 69 6e 20 6d 79 |s unlike|ly in my|
|00005780| 20 6c 69 66 65 74 69 6d | 65 20 2a 2f 0a 58 20 20 | lifetim|e */.X |
|00005790| 7d 0a 58 20 20 72 65 74 | 75 72 6e 28 20 28 64 6f |}.X ret|urn( (do|
|000057a0| 75 62 6c 65 29 20 72 61 | 6e 64 6f 6d 28 29 2f 4d |uble) ra|ndom()/M|
|000057b0| 41 58 4c 4f 4e 47 20 29 | 3b 0a 58 7d 20 2f 2a 20 |AXLONG )|;.X} /* |
|000057c0| 65 6e 64 20 66 72 61 6e | 64 6f 6d 20 2a 2f 0a 58 |end fran|dom */.X|
|000057d0| 0a 58 2f 2a 20 47 65 6e | 65 72 61 74 65 20 61 20 |.X/* Gen|erate a |
|000057e0| 72 61 6e 64 6f 6d 20 69 | 6e 74 65 67 65 72 2c 20 |random i|nteger, |
|000057f0| 75 6e 69 66 6f 72 6d 6c | 79 20 64 69 73 74 72 69 |uniforml|y distri|
|00005800| 62 75 74 65 64 20 69 6e | 20 74 68 65 20 72 61 6e |buted in| the ran|
|00005810| 67 65 20 30 2e 2e 6d 2d | 31 2e 0a 58 20 2a 20 57 |ge 0..m-|1..X * W|
|00005820| 65 20 75 73 65 20 74 68 | 65 20 6d 6f 73 74 2d 73 |e use th|e most-s|
|00005830| 69 67 6e 69 66 69 63 61 | 6e 74 20 62 69 74 73 20 |ignifica|nt bits |
|00005840| 6f 66 20 74 68 65 20 72 | 65 73 75 6c 74 20 6f 66 |of the r|esult of|
|00005850| 20 61 20 72 61 6e 64 6f | 6d 28 29 20 63 61 6c 6c | a rando|m() call|
|00005860| 2c 0a 58 20 2a 20 61 6c | 74 68 6f 75 67 68 20 74 |,.X * al|though t|
|00005870| 68 69 73 20 6d 61 79 20 | 6f 6e 6c 79 20 6d 61 72 |his may |only mar|
|00005880| 67 69 6e 61 6c 6c 79 20 | 69 6d 70 72 6f 76 65 20 |ginally |improve |
|00005890| 74 68 65 20 71 75 61 6c | 69 74 79 20 6f 66 20 6f |the qual|ity of o|
|000058a0| 75 72 20 6f 75 74 70 75 | 74 2e 0a 58 20 2a 20 59 |ur outpu|t..X * Y|
|000058b0| 6f 75 20 6d 61 79 20 77 | 69 73 68 20 74 6f 20 72 |ou may w|ish to r|
|000058c0| 65 77 72 69 74 65 20 74 | 68 69 73 20 72 6f 75 74 |ewrite t|his rout|
|000058d0| 69 6e 65 20 69 66 20 79 | 6f 75 20 64 6f 6e 27 74 |ine if y|ou don't|
|000058e0| 20 68 61 76 65 20 68 61 | 72 64 77 61 72 65 0a 58 | have ha|rdware.X|
|000058f0| 20 2a 20 66 6c 6f 61 74 | 69 6e 67 20 70 6f 69 6e | * float|ing poin|
|00005900| 74 2e 20 20 49 66 20 79 | 6f 75 20 64 6f 2c 20 62 |t. If y|ou do, b|
|00005910| 65 20 73 75 72 65 20 74 | 6f 20 69 6e 63 6c 75 64 |e sure t|o includ|
|00005920| 65 20 74 68 65 20 63 6f | 75 6e 74 65 72 2d 62 75 |e the co|unter-bu|
|00005930| 6d 70 69 6e 67 0a 58 20 | 2a 20 63 6f 64 65 20 66 |mping.X |* code f|
|00005940| 72 6f 6d 20 66 72 61 6e | 64 6f 6d 28 29 2e 20 0a |rom fran|dom(). .|
|00005950| 58 20 2a 2f 0a 65 78 74 | 65 72 6e 20 6c 6f 6e 67 |X */.ext|ern long|
|00005960| 20 6d 72 61 6e 64 6f 6d | 20 28 6d 29 0a 6c 6f 6e | mrandom| (m).lon|
|00005970| 67 20 6d 3b 0a 58 7b 0a | 58 20 20 72 65 74 75 72 |g m;.X{.|X retur|
|00005980| 6e 28 20 28 69 6e 74 29 | 20 28 66 72 61 6e 64 6f |n( (int)| (frando|
|00005990| 6d 28 29 2a 6d 29 20 29 | 3b 0a 58 7d 20 2f 2a 20 |m()*m) )|;.X} /* |
|000059a0| 65 6e 64 20 6d 72 61 6e | 64 6f 6d 20 2a 2f 0a 58 |end mran|dom */.X|
|000059b0| 0a 58 2f 2a 20 53 61 76 | 65 20 74 68 65 20 52 4e |.X/* Sav|e the RN|
|000059c0| 47 20 73 74 61 74 65 20 | 74 6f 20 61 20 73 74 61 |G state |to a sta|
|000059d0| 74 65 66 69 6c 65 2c 20 | 61 66 74 65 72 20 63 61 |tefile, |after ca|
|000059e0| 6c 6c 69 6e 67 20 72 61 | 6e 64 6f 6d 28 29 20 65 |lling ra|ndom() e|
|000059f0| 6e 6f 75 67 68 0a 58 20 | 2a 20 74 69 6d 65 73 20 |nough.X |* times |
|00005a00| 74 6f 20 72 65 73 65 74 | 20 69 74 73 20 69 6e 74 |to reset| its int|
|00005a10| 65 72 6e 61 6c 20 73 74 | 61 74 65 20 76 61 72 69 |ernal st|ate vari|
|00005a20| 61 62 6c 65 73 20 74 6f | 20 74 68 65 69 72 20 69 |ables to| their i|
|00005a30| 6e 69 74 69 61 6c 20 76 | 61 6c 75 65 73 2e 0a 58 |nitial v|alues..X|
|00005a40| 20 2a 20 43 68 65 63 6b | 20 74 6f 20 62 65 20 73 | * Check| to be s|
|00005a50| 75 72 65 20 74 68 65 20 | 52 4e 47 20 63 61 6e 20 |ure the |RNG can |
|00005a60| 62 65 20 72 65 73 74 61 | 72 74 65 64 20 62 79 20 |be resta|rted by |
|00005a70| 63 61 6c 6c 69 6e 67 20 | 72 65 73 74 61 72 74 5f |calling |restart_|
|00005a80| 72 6e 67 28 29 2e 0a 58 | 20 2a 20 52 65 74 75 72 |rng()..X| * Retur|
|00005a90| 6e 20 30 20 69 66 20 61 | 20 70 72 6f 62 6c 65 6d |n 0 if a| problem|
|00005aa0| 20 69 73 20 64 65 74 65 | 63 74 65 64 2c 20 70 72 | is dete|cted, pr|
|00005ab0| 69 6e 74 69 6e 67 20 61 | 6e 20 65 72 72 6f 72 20 |inting a|n error |
|00005ac0| 6d 65 73 73 61 67 65 20 | 6f 6e 20 73 74 64 65 72 |message |on stder|
|00005ad0| 72 2e 0a 58 20 2a 20 4f | 74 68 65 72 77 69 73 65 |r..X * O|therwise|
|00005ae0| 20 72 65 74 75 72 6e 20 | 31 2e 0a 58 20 2a 2f 0a | return |1..X */.|
|00005af0| 65 78 74 65 72 6e 20 69 | 6e 74 20 73 61 76 65 5f |extern i|nt save_|
|00005b00| 72 6e 67 28 66 69 6c 65 | 6e 61 6d 65 29 0a 63 68 |rng(file|name).ch|
|00005b10| 61 72 20 2a 66 69 6c 65 | 6e 61 6d 65 3b 0a 58 7b |ar *file|name;.X{|
|00005b20| 0a 58 20 20 46 49 4c 45 | 20 2a 66 70 3b 0a 58 20 |.X FILE| *fp;.X |
|00005b30| 20 6c 6f 6e 67 20 69 3b | 0a 58 0a 58 20 20 2f 2a | long i;|.X.X /*|
|00005b40| 20 77 72 69 74 65 20 74 | 68 65 20 73 74 61 74 65 | write t|he state|
|00005b50| 66 69 6c 65 20 2a 2f 0a | 58 20 20 66 70 20 3d 20 |file */.|X fp = |
|00005b60| 66 6f 70 65 6e 28 66 69 | 6c 65 6e 61 6d 65 2c 20 |fopen(fi|lename, |
|00005b70| 22 77 22 29 3b 0a 58 20 | 20 69 66 20 28 21 66 70 |"w");.X | if (!fp|
|00005b80| 29 20 7b 0a 58 20 20 20 | 20 66 70 72 69 6e 74 66 |) {.X | fprintf|
|00005b90| 28 73 74 64 65 72 72 2c | 20 22 54 72 6f 75 62 6c |(stderr,| "Troubl|
|00005ba0| 65 20 6f 70 65 6e 69 6e | 67 20 52 4e 47 20 73 74 |e openin|g RNG st|
|00005bb0| 61 74 65 66 69 6c 65 20 | 25 73 20 66 6f 72 20 77 |atefile |%s for w|
|00005bc0| 72 69 74 69 6e 67 2e 22 | 2c 20 66 69 6c 65 6e 61 |riting."|, filena|
|00005bd0| 6d 65 29 3b 0a 58 20 20 | 20 20 66 66 6c 75 73 68 |me);.X | fflush|
|00005be0| 28 73 74 64 65 72 72 29 | 3b 0a 58 20 20 20 20 72 |(stderr)|;.X r|
|00005bf0| 65 74 75 72 6e 28 30 29 | 3b 0a 58 20 20 7d 0a 58 |eturn(0)|;.X }.X|
|00005c00| 20 20 66 70 72 69 6e 74 | 66 28 66 70 2c 20 52 4e | fprint|f(fp, RN|
|00005c10| 47 66 69 6c 65 4c 49 4e | 45 31 2c 20 52 4e 47 73 |GfileLIN|E1, RNGs|
|00005c20| 65 65 64 29 3b 0a 58 20 | 20 66 70 72 69 6e 74 66 |eed);.X | fprintf|
|00005c30| 28 66 70 2c 20 52 4e 47 | 66 69 6c 65 4c 49 4e 45 |(fp, RNG|fileLINE|
|00005c40| 32 2c 20 52 4e 47 63 6f | 75 6e 74 32 2c 20 52 4e |2, RNGco|unt2, RN|
|00005c50| 47 63 6f 75 6e 74 31 29 | 3b 0a 58 20 20 66 70 72 |Gcount1)|;.X fpr|
|00005c60| 69 6e 74 66 28 66 70 2c | 20 52 4e 47 66 69 6c 65 |intf(fp,| RNGfile|
|00005c70| 4c 49 4e 45 33 29 3b 0a | 58 20 20 66 6f 72 20 28 |LINE3);.|X for (|
|00005c80| 69 3d 30 3b 20 69 3c 52 | 4e 47 53 54 41 54 45 4c |i=0; i<R|NGSTATEL|
|00005c90| 45 4e 47 54 48 3b 20 69 | 2b 3d 34 29 20 7b 0a 58 |ENGTH; i|+=4) {.X|
|00005ca0| 20 20 20 20 66 70 72 69 | 6e 74 66 28 66 70 2c 20 | fpri|ntf(fp, |
|00005cb0| 52 4e 47 66 69 6c 65 4c | 49 4e 45 6e 2c 0a 58 09 |RNGfileL|INEn,.X.|
|00005cc0| 20 20 20 20 72 6e 67 73 | 74 61 74 65 5b 69 5d 2c | rngs|tate[i],|
|00005cd0| 20 72 6e 67 73 74 61 74 | 65 5b 69 2b 31 5d 2c 20 | rngstat|e[i+1], |
|00005ce0| 72 6e 67 73 74 61 74 65 | 5b 69 2b 32 5d 2c 20 72 |rngstate|[i+2], r|
|00005cf0| 6e 67 73 74 61 74 65 5b | 69 2b 33 5d 29 3b 0a 58 |ngstate[|i+3]);.X|
|00005d00| 20 20 7d 0a 58 20 20 66 | 70 72 69 6e 74 66 28 66 | }.X f|printf(f|
|00005d10| 70 2c 20 52 4e 47 66 69 | 6c 65 4c 49 4e 45 31 32 |p, RNGfi|leLINE12|
|00005d20| 2c 20 6e 65 78 74 76 61 | 6c 28 29 29 3b 0a 58 20 |, nextva|l());.X |
|00005d30| 20 66 63 6c 6f 73 65 28 | 66 70 29 3b 0a 58 0a 58 | fclose(|fp);.X.X|
|00005d40| 20 20 2f 2a 20 52 65 74 | 75 72 6e 20 61 66 74 65 | /* Ret|urn afte|
|00005d50| 72 20 63 68 65 63 6b 69 | 6e 67 20 74 68 61 74 20 |r checki|ng that |
|00005d60| 73 74 61 74 65 20 77 61 | 73 20 73 61 76 65 64 20 |state wa|s saved |
|00005d70| 63 6f 72 72 65 63 74 6c | 79 2e 20 2a 2f 0a 58 20 |correctl|y. */.X |
|00005d80| 20 72 65 74 75 72 6e 28 | 20 72 65 73 74 61 72 74 | return(| restart|
|00005d90| 5f 72 6e 67 28 66 69 6c | 65 6e 61 6d 65 29 20 29 |_rng(fil|ename) )|
|00005da0| 3b 0a 58 0a 58 7d 20 2f | 2a 20 65 6e 64 20 73 61 |;.X.X} /|* end sa|
|00005db0| 76 65 5f 72 6e 67 20 2a | 2f 0a 58 0a 58 2f 2a 20 |ve_rng *|/.X.X/* |
|00005dc0| 65 6e 64 20 6d 72 61 6e | 64 6f 6d 2e 63 20 2a 2f |end mran|dom.c */|
|00005dd0| 0a 45 4e 44 5f 4f 46 5f | 46 49 4c 45 0a 69 66 20 |.END_OF_|FILE.if |
|00005de0| 74 65 73 74 20 31 30 35 | 36 39 20 2d 6e 65 20 60 |test 105|69 -ne `|
|00005df0| 77 63 20 2d 63 20 3c 27 | 6d 72 61 6e 64 6f 6d 2e |wc -c <'|mrandom.|
|00005e00| 63 27 60 3b 20 74 68 65 | 6e 0a 20 20 20 20 65 63 |c'`; the|n. ec|
|00005e10| 68 6f 20 73 68 61 72 3a | 20 5c 22 27 6d 72 61 6e |ho shar:| \"'mran|
|00005e20| 64 6f 6d 2e 63 27 5c 22 | 20 75 6e 70 61 63 6b 65 |dom.c'\"| unpacke|
|00005e30| 64 20 77 69 74 68 20 77 | 72 6f 6e 67 20 73 69 7a |d with w|rong siz|
|00005e40| 65 21 0a 66 69 0a 23 20 | 65 6e 64 20 6f 66 20 27 |e!.fi.# |end of '|
|00005e50| 6d 72 61 6e 64 6f 6d 2e | 63 27 0a 66 69 0a 69 66 |mrandom.|c'.fi.if|
|00005e60| 20 74 65 73 74 20 2d 66 | 20 27 6d 72 61 6e 64 6f | test -f| 'mrando|
|00005e70| 6d 2e 68 27 20 2d 61 20 | 22 24 7b 31 7d 22 20 21 |m.h' -a |"${1}" !|
|00005e80| 3d 20 22 2d 63 22 20 3b | 20 74 68 65 6e 20 0a 20 |= "-c" ;| then . |
|00005e90| 20 65 63 68 6f 20 73 68 | 61 72 3a 20 57 69 6c 6c | echo sh|ar: Will|
|00005ea0| 20 6e 6f 74 20 63 6c 6f | 62 62 65 72 20 65 78 69 | not clo|bber exi|
|00005eb0| 73 74 69 6e 67 20 66 69 | 6c 65 20 5c 22 27 6d 72 |sting fi|le \"'mr|
|00005ec0| 61 6e 64 6f 6d 2e 68 27 | 5c 22 0a 65 6c 73 65 0a |andom.h'|\".else.|
|00005ed0| 65 63 68 6f 20 73 68 61 | 72 3a 20 45 78 74 72 61 |echo sha|r: Extra|
|00005ee0| 63 74 69 6e 67 20 5c 22 | 27 6d 72 61 6e 64 6f 6d |cting \"|'mrandom|
|00005ef0| 2e 68 27 5c 22 20 5c 28 | 32 33 37 39 20 63 68 61 |.h'\" \(|2379 cha|
|00005f00| 72 61 63 74 65 72 73 5c | 29 0a 73 65 64 20 22 73 |racters\|).sed "s|
|00005f10| 2f 5e 58 2f 2f 22 20 3e | 27 6d 72 61 6e 64 6f 6d |/^X//" >|'mrandom|
|00005f20| 2e 68 27 20 3c 3c 27 45 | 4e 44 5f 4f 46 5f 46 49 |.h' <<'E|ND_OF_FI|
|00005f30| 4c 45 27 0a 58 2f 2a 0a | 58 20 2a 09 09 6d 72 61 |LE'.X/*.|X *..mra|
|00005f40| 6e 64 6f 6d 2e 68 0a 58 | 20 2a 0a 58 20 2a 09 41 |ndom.h.X| *.X *.A|
|00005f50| 20 77 72 61 70 70 65 72 | 20 66 6f 72 20 72 61 6e | wrapper| for ran|
|00005f60| 64 6f 6d 28 29 2c 20 74 | 6f 20 61 6c 6c 6f 77 20 |dom(), t|o allow |
|00005f70| 73 61 66 65 20 72 65 73 | 74 61 72 74 2e 0a 58 20 |safe res|tart..X |
|00005f80| 2a 0a 58 20 2a 09 4f 72 | 69 67 69 6e 61 6c 20 49 |*.X *.Or|iginal I|
|00005f90| 6d 70 6c 65 6d 65 6e 74 | 61 74 69 6f 6e 3a 0a 58 |mplement|ation:.X|
|00005fa0| 20 2a 09 09 43 6c 61 72 | 6b 20 54 68 6f 6d 62 6f | *..Clar|k Thombo|
|00005fb0| 72 73 6f 6e 2c 20 53 65 | 70 74 65 6d 62 65 72 20 |rson, Se|ptember |
|00005fc0| 31 39 39 31 0a 58 20 2a | 0a 58 20 2a 09 54 68 69 |1991.X *|.X *.Thi|
|00005fd0| 73 20 6d 61 74 65 72 69 | 61 6c 20 69 73 20 62 61 |s materi|al is ba|
|00005fe0| 73 65 64 20 75 70 6f 6e | 20 77 6f 72 6b 20 73 75 |sed upon| work su|
|00005ff0| 70 70 6f 72 74 65 64 20 | 62 79 20 74 68 65 20 4e |pported |by the N|
|00006000| 61 74 69 6f 6e 61 6c 0a | 58 20 2a 09 53 63 69 65 |ational.|X *.Scie|
|00006010| 6e 63 65 20 46 6f 75 6e | 64 61 74 69 6f 6e 20 75 |nce Foun|dation u|
|00006020| 6e 64 65 72 20 67 72 61 | 6e 74 20 6e 75 6d 62 65 |nder gra|nt numbe|
|00006030| 72 20 4d 49 50 2d 39 30 | 32 33 32 33 38 2e 20 20 |r MIP-90|23238. |
|00006040| 54 68 65 0a 58 20 2a 09 | 47 6f 76 65 72 6e 6d 65 |The.X *.|Governme|
|00006050| 6e 74 20 68 61 73 20 63 | 65 72 74 61 69 6e 20 72 |nt has c|ertain r|
|00006060| 69 67 68 74 73 20 69 6e | 20 74 68 69 73 20 6d 61 |ights in| this ma|
|00006070| 74 65 72 69 61 6c 2e 0a | 58 20 2a 0a 58 20 2a 09 |terial..|X *.X *.|
|00006080| 41 6e 79 20 6f 70 69 6e | 69 6f 6e 73 2c 20 66 69 |Any opin|ions, fi|
|00006090| 6e 64 69 6e 67 73 2c 20 | 61 6e 64 20 63 6f 6e 63 |ndings, |and conc|
|000060a0| 6c 75 73 69 6f 6e 73 20 | 6f 72 20 72 65 63 6f 6d |lusions |or recom|
|000060b0| 6d 65 6e 64 61 74 69 6f | 6e 73 0a 58 20 2a 09 65 |mendatio|ns.X *.e|
|000060c0| 78 70 72 65 73 73 65 64 | 20 69 6e 20 74 68 69 73 |xpressed| in this|
|000060d0| 20 6d 61 74 65 72 69 61 | 6c 20 61 72 65 20 74 68 | materia|l are th|
|000060e0| 6f 73 65 20 6f 66 20 74 | 68 65 20 61 75 74 68 6f |ose of t|he autho|
|000060f0| 72 20 61 6e 64 20 64 6f | 0a 58 20 2a 09 6e 6f 74 |r and do|.X *.not|
|00006100| 20 6e 65 63 65 73 73 61 | 72 69 6c 79 20 72 65 66 | necessa|rily ref|
|00006110| 6c 65 63 74 20 74 68 65 | 20 76 69 65 77 20 6f 66 |lect the| view of|
|00006120| 20 74 68 65 20 4e 61 74 | 69 6f 6e 61 6c 20 53 63 | the Nat|ional Sc|
|00006130| 69 65 6e 63 65 0a 58 20 | 2a 09 46 6f 75 6e 64 61 |ience.X |*.Founda|
|00006140| 74 69 6f 6e 2e 0a 58 20 | 2a 0a 58 20 2a 09 54 68 |tion..X |*.X *.Th|
|00006150| 69 73 20 63 6f 64 65 20 | 69 73 20 6e 65 69 74 68 |is code |is neith|
|00006160| 65 72 20 63 6f 70 79 72 | 69 67 68 74 65 64 20 6e |er copyr|ighted n|
|00006170| 6f 72 20 70 61 74 65 6e | 74 65 64 2e 0a 58 20 2a |or paten|ted..X *|
|00006180| 2f 0a 58 0a 58 23 64 65 | 66 69 6e 65 20 52 4e 47 |/.X.X#de|fine RNG|
|00006190| 49 44 53 54 52 4c 45 4e | 20 38 30 20 2f 2a 20 6d |IDSTRLEN| 80 /* m|
|000061a0| 61 78 20 6c 65 6e 67 74 | 68 20 6f 66 20 73 74 72 |ax lengt|h of str|
|000061b0| 69 6e 67 20 77 72 69 74 | 74 65 6e 20 62 79 20 64 |ing writ|ten by d|
|000061c0| 65 73 63 72 69 62 65 5f | 72 6e 67 28 29 20 2a 2f |escribe_|rng() */|
|000061d0| 0a 58 0a 63 68 61 72 20 | 2a 64 65 73 63 72 69 62 |.X.char |*describ|
|000061e0| 65 5f 72 6e 67 20 28 2f | 2a 20 63 68 61 72 20 72 |e_rng (/|* char r|
|000061f0| 6e 67 69 64 5b 52 4e 47 | 49 44 53 54 52 4c 45 4e |ngid[RNG|IDSTRLEN|
|00006200| 5d 20 2a 2f 29 3b 0a 58 | 2f 2a 20 57 72 69 74 65 |] */);.X|/* Write|
|00006210| 20 61 20 52 4e 47 20 73 | 74 61 74 65 20 69 64 65 | a RNG s|tate ide|
|00006220| 6e 74 69 66 69 65 72 20 | 69 6e 74 6f 20 74 68 65 |ntifier |into the|
|00006230| 20 75 73 65 72 2d 73 75 | 70 70 6c 69 65 64 20 73 | user-su|pplied s|
|00006240| 74 72 69 6e 67 20 72 6e | 67 69 64 2c 0a 58 20 2a |tring rn|gid,.X *|
|00006250| 20 77 68 69 63 68 20 6d | 75 73 74 20 62 65 20 6f | which m|ust be o|
|00006260| 66 20 6c 65 6e 67 74 68 | 20 61 74 20 6c 65 61 73 |f length| at leas|
|00006270| 74 20 52 4e 47 49 44 53 | 54 52 4c 45 4e 2e 20 20 |t RNGIDS|TRLEN. |
|00006280| 49 66 20 74 68 65 20 75 | 73 65 72 20 68 61 73 20 |If the u|ser has |
|00006290| 6e 6f 74 0a 58 20 2a 20 | 69 6e 69 74 69 61 6c 69 |not.X * |initiali|
|000062a0| 7a 65 64 20 74 68 65 20 | 72 6e 67 20 77 69 74 68 |zed the |rng with|
|000062b0| 20 69 6e 69 74 5f 72 6e | 67 28 29 2c 20 72 65 73 | init_rn|g(), res|
|000062c0| 74 61 72 74 5f 72 6e 67 | 28 29 2c 20 6f 72 20 72 |tart_rng|(), or r|
|000062d0| 65 63 6f 6e 73 74 72 75 | 63 74 5f 72 6e 67 28 29 |econstru|ct_rng()|
|000062e0| 2c 0a 58 20 2a 20 61 62 | 6f 72 74 20 77 69 74 68 |,.X * ab|ort with|
|000062f0| 20 61 6e 20 65 72 72 6f | 72 20 6d 65 73 73 61 67 | an erro|r messag|
|00006300| 65 20 74 6f 20 73 74 64 | 65 72 72 2e 20 20 4f 74 |e to std|err. Ot|
|00006310| 68 65 72 77 69 73 65 20 | 72 65 74 75 72 6e 20 74 |herwise |return t|
|00006320| 68 65 20 76 61 6c 75 65 | 20 6f 66 20 72 6e 67 69 |he value| of rngi|
|00006330| 64 2e 0a 58 20 2a 2f 0a | 58 0a 69 6e 74 20 69 6e |d..X */.|X.int in|
|00006340| 69 74 5f 72 6e 67 20 28 | 2f 2a 20 6c 6f 6e 67 20 |it_rng (|/* long |
|00006350| 73 65 65 64 3b 20 63 68 | 61 72 20 2a 66 69 6c 65 |seed; ch|ar *file|
|00006360| 6e 61 6d 65 3b 20 2a 2f | 29 3b 0a 58 2f 2a 20 43 |name; */|);.X/* C|
|00006370| 72 65 61 74 65 20 61 20 | 72 61 6e 64 6f 6d 20 6e |reate a |random n|
|00006380| 75 6d 62 65 72 20 73 74 | 61 74 65 66 69 6c 65 20 |umber st|atefile |
|00006390| 69 6e 69 74 69 61 6c 69 | 7a 65 64 20 77 69 74 68 |initiali|zed with|
|000063a0| 20 74 68 65 20 67 69 76 | 65 6e 20 73 65 65 64 2e | the giv|en seed.|
|000063b0| 0a 58 20 2a 20 52 65 74 | 75 72 6e 20 31 20 69 66 |.X * Ret|urn 1 if|
|000063c0| 20 66 69 6c 65 20 69 73 | 20 73 75 63 63 65 73 73 | file is| success|
|000063d0| 66 75 6c 6c 79 20 63 72 | 65 61 74 65 64 2c 20 30 |fully cr|eated, 0|
|000063e0| 20 6f 74 68 65 72 77 69 | 73 65 2e 0a 58 20 2a 2f | otherwi|se..X */|
|000063f0| 0a 58 0a 69 6e 74 20 72 | 65 73 74 61 72 74 5f 72 |.X.int r|estart_r|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.