home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume28 / mrandom-3.0 / part05 < prev    next >
Text File  |  1994-05-06  |  88KB  |  1,303 lines

  1. Newsgroups: comp.sources.unix
  2. From: cthombor@theory.lcs.mit.edu (Clark D. Thomborson)
  3. Subject: v28i031: mrandom-3.0 - random number generator with persistent state, Part05/06
  4. References: <1.768285901.18944@gw.home.vix.com>
  5. Sender: unix-sources-moderator@gw.home.vix.com
  6. Approved: vixie@gw.home.vix.com
  7.  
  8. Submitted-By: cthombor@theory.lcs.mit.edu (Clark D. Thomborson)
  9. Posting-Number: Volume 28, Issue 31
  10. Archive-Name: mrandom-3.0/part05
  11.  
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 5 (of 6)."
  19. # Contents:  doc/mrandom.ps.2
  20. # Wrapped by vixie@gw.home.vix.com on Fri May  6 21:42:56 1994
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'doc/mrandom.ps.2' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'doc/mrandom.ps.2'\"
  24. else
  25. echo shar: Extracting \"'doc/mrandom.ps.2'\" \(85170 characters\)
  26. sed "s/^X//" >'doc/mrandom.ps.2' <<'END_OF_FILE'
  27. X%%Page: 2 5
  28. Xbop 262 162 a Fi(2)41 b(FILES)14 b(IN)g(THE)g(DISTRIBUTION)g(DIRECTOR)m(Y)468
  29. Xb Fl(2)262 307 y Fk(2)69 b(Files)21 b(in)h(the)g(Distribution)f(Directory)262
  30. X398 y Fl(The)14 b(mrandom)d(source)k(co)q(de)g(distribution)e(includes)h(the)
  31. Xh(follo)o(wing)c(\014les:)262 489 y Fh(mak)o(e\014le)19 b Fl(The)g(mak)o
  32. X(e\014le)d(for)j(creating)f(the)h Ff(mrtest)e Fl(program)g(and)h(the)i
  33. XFf(mrandom.a)365 539 y Fl(library)m(.)262 622 y Fh(README)h
  34. XFl(General)9 b(information)d(ab)q(out)k(the)g(mrandom)c(pac)o(k)n(age,)j
  35. X(including)f(c)o(hanges)365 672 y(to)14 b(the)h(last)e(v)o(ersion.)262
  36. X755 y Fh(mrandom.c)h(mrandom.h)19 b Fl(The)14 b(source)i(and)d(header)i
  37. X(\014les)g(for)e(the)i(main)d(mrandom)365 805 y(mo)q(dule.)262
  38. X888 y Fh(b)q(en)o(tley)l(.c)i(b)q(en)o(tley)l(.h)k Fl(The)f(source)h(and)e
  39. X(header)h(\014les)g(for)f(Ben)o(tley's)h(v)o(ersion)f(of)g(the)365
  40. X938 y(generator)f(describ)q(ed)h(in)d(Kn)o(uth)h(V)m(ol)f(2,)g(Section)i
  41. X(3.6.)262 1021 y Fh(p)q(crand.c)g(p)q(crand.h)k Fl(The)g(source)h(and)e
  42. X(header)h(\014les)f(for)g(the)h(P)o(ortable)f(Com)o(bined)365
  43. X1071 y(RNG.)262 1154 y Fh(ran0.c)d(ran0.h)g(ran1.c)h(ran1.h)f(ran2.c)g
  44. X(ran2.h)20 b Fl(The)12 b(source)h(and)f(header)h(\014les)f(for)365
  45. X1203 y(Press)k(and)e(T)m(euk)o(olsky's)f(ran0,)g(ran1,)g(and)h(ran2.)262
  46. X1286 y Fh(ultra.c)g(ultra.h)19 b Fl(The)14 b(source)h(and)f(header)h(\014les)
  47. Xf(for)g(Marsaglia's)e(Ultra)i(generator.)262 1369 y Fh(mrtest.c)19
  48. Xb Fl(The)14 b(mrtest)g(source)h(\014le.)262 1452 y Fh(xsq.c)h(xsq.h)21
  49. Xb Fl(Co)q(de)14 b(used)h(b)o(y)f(mrtest.)262 1536 y Fh(rngs.h)19
  50. Xb Fl(The)14 b(header)h(\014le)f(for)g(the)g(UNIX)g(RNGs)g(and)f(the)i
  51. X(trivial)d(RNG.)262 1619 y Fh(newrng.c)j(newrng.h)k Fl(Source)c(and)f(header)
  52. Xh(\014le)f(templates)f(for)h(a)f(new)h(RNG.)262 1702 y Fh(mrandom.3)19
  53. Xb Fl(The)14 b(man)e(pages)j(for)e(mrandom.)262 1785 y Fh(mrtest.1)19
  54. Xb Fl(The)14 b(man)e(pages)i(for)g(mrtest.)262 1868 y Fh(script)k
  55. XFl(A)c(test)h(script)g(for)e(mrtest.)262 1951 y Fh(mrandom.tex)19
  56. Xb Fl(The)14 b(latex)f(source)j(for)d(this)h(man)o(ual.)262
  57. X2034 y Fh(latexinfo.st)n(y)k Fl(The)c(st)o(yle)h(\014le)e(needed)j(to)e
  58. X(latex)f(this)h(man)o(ual.)262 2117 y Fh(mrandom.txt)k Fl(Plain)13
  59. Xb(ASCI)q(I)h(text)h(v)o(ersion)f(of)f(this)h(man)o(ual.)262
  60. X2200 y Fh(mrandom.ps)k Fl(P)o(ostScript)d(v)o(ersion)f(of)f(this)h(man)o
  61. X(ual.)p eop
  62. X%%Page: 3 6
  63. Xbop 262 162 a Fi(3)41 b(INST)m(ALLING)13 b(MRANDOM)845 b Fl(3)262
  64. X307 y Fk(3)69 b(Installing)21 b(mrandom)262 398 y Fl(Preparing)16
  65. Xb(the)h(mrandom)c(pac)o(k)n(age)j(for)g(use)h(b)o(y)f(other)h(programs)e(is)h
  66. X(simple.)24 b(Merely)262 448 y(p)q(osition)13 b(y)o(ourself)g(in)h(the)g
  67. X(directory)h(whic)o(h)f(con)o(tains)g(the)g(mrandom)d(\014les)j(and)g(t)o(yp)
  68. Xq(e:)324 548 y Ff(make)21 b(all)324 647 y Fl(This)12 b(will)e(compile)g(all)h
  69. X(necessary)j(source)f(\014les)g(and)e(create)j(the)e Ff(mrandom.a)e
  70. XFl(library)m(,)262 697 y(as)j(w)o(ell)h(as)g(the)g Ff(mrtest)f
  71. XFl(binary)g(executable.)324 747 y(Y)m(ou)i(can)i(also)e(mak)o(e)g(either)i
  72. X(the)g Ff(mrandom.a)d Fl(library)i(or)g(the)g Ff(mrtest)f Fl(executable)262
  73. X797 y(b)o(y)e(t)o(yping:)324 896 y Ff(make)21 b(mrandom.a)324
  74. X996 y Fl(or)324 1095 y Ff(make)g(mrtest)262 1195 y Fl(resp)q(ectiv)o(ely)m(.)
  75. X324 1245 y(T)m(o)13 b(sa)o(v)o(e)h(disk)g(space,)g(v)n(arious)f(in)o
  76. X(termediate)g(ob)r(ject)i(\014les)f(can)g(b)q(e)h(remo)o(v)o(ed)e(with:)324
  77. X1345 y Ff(make)21 b(clean)324 1444 y Fl(The)14 b(system)g(can)g(b)q(e)g
  78. X(restored)i(to)e(its)g(original)e(state)i(with:)324 1544 y
  79. XFf(make)21 b(realclean)324 1643 y Fl(The)14 b(mrandom)e(pac)o(k)n(age)h(is)h
  80. X(written)h(in)f(ANSI)g(C,)g(and)g(should)g(b)q(e)h(easily)e(p)q(ortable)262
  81. X1693 y(to)h(an)o(y)g(UNIX-based)i(system)e(supp)q(orting)h(a)f(C)h(language)e
  82. X(compiler.)19 b(Ho)o(w)o(ev)o(er,)c(when)262 1743 y(compiling)8
  83. Xb(on)j(a)g(new)h(system,)f(con\014rm)g(that)g(the)h Ff(long)f
  84. XFl(t)o(yp)q(e)h(is)f(represen)o(ted)j(in)d(32)g(bits.)262 1880
  85. Xy Fk(4)69 b(What)23 b(is)f(an)i(RNG?)262 1971 y Fl(Within)9
  86. Xb(the)j(mrandom)7 b(pac)o(k)n(age,)k(an)g(RNG)f(is)g(represen)o(ted)k(b)o(y)c
  87. X(the)i Ff(RNGdata)d Fl(structure.)262 2021 y(An)i(RNG)g(has)h(sev)o(eral)g
  88. X(abstract)g(c)o(haracteristics)i(whic)o(h)d(are)h(describ)q(ed)i(in)d(this)g
  89. X(section.)262 2071 y(F)m(or)j(a)g(more)g(detailed)h(description)g(of)g(the)g
  90. X(represen)o(tation)h(of)f(the)g Ff(RNGdata)e Fl(structure)262
  91. X2121 y(in)g(C,)g(see)i(App)q(endix)g(A.)324 2171 y(Asso)q(ciated)g(with)e(ev)
  92. Xo(ery)i(RNG)e(is:)324 2254 y Fe(\017)20 b Fl(an)d(algorithm)d(n)o(um)o(b)q
  93. X(er,)j(whic)o(h)f(determines)i(whic)o(h)f(algorithm)d(the)j(RNG)f(uses)365
  94. X2303 y(to)h(pro)q(duce)h(pseudorandom)e(generates.)29 b(F)m(or)16
  95. Xb(descriptions)i(of)e(the)i(algorithms)365 2353 y(whic)o(h)c(are)g(curren)o
  96. X(tly)h(installed)e(in)h(the)g(pac)o(k)n(age,)f(see)j(App)q(endix)e(B.)p
  97. Xeop
  98. X%%Page: 4 7
  99. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)645
  100. Xb Fl(4)324 307 y Fe(\017)20 b Fl(an)13 b(\\mrandom)e(algorithm)f(n)o(um)o(b)q
  101. X(er,")i(whic)o(h)h(determines)h(whic)o(h)f(algorithm)e(the)365
  102. X357 y Ff(mrandomrv)d Fl(routine)h(will)f(use)i(to)f(pro)q(duce)i
  103. X(restricted-range)g(in)o(tegers)f(when)g(called)365 407 y(with)h(the)h(RNG.)d
  104. X(\(See)j(the)g(description)f(of)g Ff(mrandomrv)e Fl(in)h(Section)i(5.4.2)d
  105. X(for)i(more)365 457 y(information.\))324 533 y Fe(\017)20 b
  106. XFl(a)14 b(state)h(v)o(ector,)f(whic)o(h)g(con)o(tains)f(the)i(curren)o(t)g
  107. X(state)g(of)e(the)i(RNG.)324 609 y Fe(\017)20 b Fl(the)15 b(size)f(of)g(the)g
  108. X(state)h(v)o(ector.)324 685 y Fe(\017)20 b Fl(a)12 b(seed)i(v)o(ector,)f
  109. X(whic)o(h)f(con)o(tains)g(the)h(seeds)h(whic)o(h)f(w)o(ere)g(used)g(to)f
  110. X(seed)i(the)f(RNG.)324 762 y Fe(\017)20 b Fl(the)15 b(size)f(of)g(the)g(seed)
  111. Xh(v)o(ector.)324 838 y Fe(\017)20 b Fl(a)f(coun)o(t)g(of)g(the)h(n)o(um)o(b)q
  112. X(er)e(of)h(times)f(the)h(RNG)g(has)g(b)q(een)h(called)f(since)h(it)f(w)o(as)
  113. X365 888 y(initialized.)324 964 y Fe(\017)h Fl(t)o(w)o(o)14
  114. Xb(bu\013ers)412 1040 y Fh({)21 b Fl(a)13 b(bit)h(bu\013er)h(for)e(bit)h
  115. X(generates)412 1100 y Fh({)21 b Fl(a)13 b(main)f(bu\013er)j(for)e(all)g
  116. X(other)i(generates.)365 1176 y(See)g(Section)f(5.4.2)f(for)g(a)h(description)
  117. Xg(of)f(ho)o(w)h(the)g(t)o(w)o(o)g(bu\013ers)h(w)o(ork.)324
  118. X1252 y Fe(\017)20 b Fl(a)11 b(split)f(v)n(alue,)g(whic)o(h)g(determines)h(ho)
  119. Xo(w)f(man)o(y)f(generates)j(to)f(skip)f(b)q(et)o(w)o(een)i(v)n(alues)365
  120. X1302 y(whic)o(h)j(are)f(returned)j(from)12 b(the)j(RNG.)f(F)m(or)g(a)g
  121. X(detailed)g(description)h(of)f(the)h(split)365 1352 y(v)n(alue,)e(see)i
  122. X(Section)f(5.4.7.)324 1428 y Fe(\017)20 b Fl(a)14 b(string)g(con)o(taining)f
  123. X(the)h(h)o(uman-readable)f(name)f(of)h(the)i(RNG.)324 1504
  124. Xy Fe(\017)20 b Fl(the)12 b(range)g(of)f(the)h(RNG,)e(suc)o(h)i(that)g(the)g
  125. X(RNG)f(is)g(capable)g(of)g(pro)q(ducing)h(in)o(tegers)365 1554
  126. Xy(with)i(a)f(maxim)o(um)c(v)n(alue)k(of)h(range-1.)262 1689
  127. Xy Fk(5)69 b(Using)22 b(the)h(mrandom)g(pac)n(k)l(age)262 1788
  128. Xy Fd(5.1)55 b(Ov)n(erview)18 b(of)g(the)h(Library)262 1864
  129. Xy Fl(This)14 b(section)i(describ)q(es)g(the)g(mrandom)11 b(library)m(.)20
  130. Xb(The)15 b(pro)q(cedures)i(in)d(the)h(library)f(are)262 1914
  131. Xy(gathered)g(in)o(to)f(the)i(follo)o(wing)c(groups:)324 1984
  132. Xy Fe(\017)20 b Fl(functions)14 b(for)g(initializing)d(and)j(de-initializing)d
  133. X(\(killing\))h(RNGs)324 2060 y Fe(\017)20 b Fl(functions)14
  134. Xb(for)g(returning)g(generates)i(from)c(RNGs)324 2136 y Fe(\017)20
  135. Xb Fl(functions)14 b(for)g(sa)o(ving)f(and)h(restarting)g(RNGs)324
  136. X2212 y Fe(\017)20 b Fl(a)14 b(function)f(for)h(seeding)h(RNGs)324
  137. X2289 y Fe(\017)20 b Fl(a)14 b(function)f(for)h(c)o(hec)o(king)g(the)h(in)o
  138. X(tegrit)o(y)e(of)g(RNG)g(state)i(v)o(ectors)324 2365 y Fe(\017)20
  139. Xb Fl(a)13 b(function)g(for)g(pro)q(ducing)h(a)f(h)o(uman-readable)e(ASCI)q(I)
  140. Xj(description)g(of)e(an)h(RNG)324 2441 y Fe(\017)20 b Fl(functions)14
  141. Xb(for)g(examining)d(and)j(mo)q(difying)d(c)o(haracteristics)16
  142. Xb(of)d(RNGs)p eop
  143. X%%Page: 5 8
  144. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)645
  145. Xb Fl(5)262 307 y Fd(5.2)55 b(Return)18 b(co)r(des)g(from)g(mrandom)e
  146. X(routines)262 384 y Fl(Most)e(mrandom)d(routines)j(follo)o(w)e(one)i(of)f(t)o
  147. X(w)o(o)h(con)o(v)o(en)o(tions)g(for)f(return)i(v)n(alues.)262
  148. X434 y(F)m(or)e(those)i(routines)f(whic)o(h)g(return)h(p)q(oin)o(ters)f(to)g
  149. X(an)g Ff(RNGdata)e Fl(structure:)324 516 y Fe(\017)20 b Fl(A)14
  150. Xb(v)n(alid)f(p)q(oin)o(ter)h(to)f(an)h Ff(RNGdata)e Fl(structure)k(is)e
  151. X(returned)i(up)q(on)e(success.)324 599 y Fe(\017)20 b Fl(A)14
  152. Xb(n)o(ull)f(p)q(oin)o(ter)h(is)g(returned)i(up)q(on)d(failure.)262
  153. X681 y(F)m(or)g(routines)h(whic)o(h)g(pro)q(duce)h(v)o(ectors)g(of)f
  154. X(pseudorandom)f(generates:)324 763 y Fe(\017)20 b Fl(The)15
  155. Xb(\014rst)f(cell)g(of)f(the)i(v)o(ector)g(is)e(returned)j(up)q(on)e(success.)
  156. X324 846 y Fe(\017)20 b Fl(The)15 b(program)d(ab)q(orts)i(up)q(on)g(error.)262
  157. X928 y(F)m(or)f(all)g(other)h(routines:)324 1010 y Fe(\017)20
  158. Xb Fl(A)14 b(0)g(or)g(-1)f(is)h(returned)h(up)q(on)f(failure.)262
  159. X1093 y(Details)f(are)h(pro)o(vided)g(in)f(the)i(description)f(of)g(the)g
  160. X(mrandom)d(library)i(in)h(Section)g(5.4.)262 1209 y Fd(5.3)55
  161. Xb(Linking)262 1285 y Fl(In)13 b(order)i(to)f(use)g(the)h(mrandom)c(library)i
  162. X(of)g(routines)i(in)e(y)o(our)h(programs)f(y)o(ou)g(m)o(ust:)324
  163. X1368 y Fe(\017)20 b Fl(Link)11 b(the)h Ff(mrandom.a)d Fl(library)i(with)g(y)o
  164. X(our)g(program.)k(This)c(will)f(t)o(ypically)g(in)o(v)o(olv)o(e)365
  165. X1417 y(merely)j(including)g(the)i(library)e(on)g(y)o(our)h(compiler's)f
  166. X(command)e(line,)i(suc)o(h)h(as:)428 1533 y Ff(cc)21 b(myprog.c)f(mrandom.a)
  167. X365 1649 y Fl(Since)e(mrandom)c(uses)k(some)f(UNIX)g(mathematical)d
  168. X(functions,)j(y)o(ou)g(ma)o(y)e(also)365 1699 y(need)g(to)f(link)f(a)g(math)g
  169. X(library)g(with)g(y)o(our)h(program,)e(as)i(in)f(the)i(follo)o(wing:)428
  170. X1815 y Ff(cc)21 b(myprog.c)f(mrandom.a)g(-lm)365 1931 y Fl(Chec)o(k)15
  171. Xb(the)f(do)q(cumen)o(tation)f(for)h(y)o(our)f(C)h(compiler)e(for)i(details.)
  172. X324 2014 y Fe(\017)20 b Fl(Include)15 b(the)f(follo)o(wing)d(line)j(at)g(the)
  173. Xg(top)g(of)f(y)o(our)h(source)h(\014le:)428 2080 y Ff(#include)20
  174. Xb("mrandom.h")262 2196 y Fd(5.4)55 b(The)19 b(mrandom)d(library)262
  175. X2273 y Fh(5.4.1)47 b(Initializati)o(on)12 b(and)k(De-Initial)o(i)o(zatio)o(n)
  176. X262 2350 y Fl(In)10 b(order)i(to)f(use)h(an)e(RNG,)g(it)h(m)o(ust)f(\014rst)h
  177. X(b)q(e)h(initialized.)j(This)c(is)g(accomplished)f(b)o(y)h(\014rst)262
  178. X2399 y(declaring)i(a)h(p)q(oin)o(ter)g(to)g(an)g Ff(RNGdata)e
  179. XFl(structure,)k(and)e(then)g(calling)f Ff(init_rng)p Fl(,)f(whic)o(h)262
  180. X2449 y(allo)q(cates)j(memory)f(for)i(the)h(RNG)e(and)h(readies)h(it)e(for)h
  181. X(use)h(b)o(y)f(the)h(other)f(routines)h(in)p eop
  182. X%%Page: 6 9
  183. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)645
  184. Xb Fl(6)262 307 y(the)14 b(pac)o(k)n(age.)324 407 y Ff(RNGdata)20
  185. Xb(*init_rng\(alg,mran)o(dom_a)o(lg,se)o(ed,co)o(unt1)o(,coun)o(t2,bu)o(fsize)
  186. Xo(\))324 457 y(long)h(alg;)324 506 y(long)g(mrandom_alg;)324
  187. X556 y(long)g(*seed;)324 606 y(long)g(count1,)f(count2;)324
  188. X656 y(long)h(bufsize;)324 756 y(int)g(kill_rng\(rng\))324 805
  189. Xy(RNGdata)f(*rng;)324 905 y(init_rng)c Fl(returns)j(a)e(p)q(oin)o(ter)h(to)f
  190. X(an)h(initialized)e(RNG.)g(A)i(p)q(oin)o(ter)g(returned)h(b)o(y)262
  191. X955 y Ff(init_rng)12 b Fl(is)h(v)n(alid)g(for)g(use)i(b)o(y)f(all)e(other)j
  192. X(mrandom)c(routines.)324 1005 y Ff(alg)i Fl(is)h(the)g(n)o(um)o(b)q(er)g(of)f
  193. X(the)i(algorithm)c(to)j(b)q(e)g(used)h(b)o(y)f(the)g(RNG.)f(\(See)i(App)q
  194. X(endix)262 1054 y(B.\))324 1104 y Ff(mrandom_alg)g Fl(is)i(the)h(algorithm)c
  195. X(to)k(b)q(e)f(used)i(b)o(y)e Ff(mrandomrv)e Fl(when)j(called)f(with)262
  196. X1154 y(the)d(RNG.)f(\(See)i(Section)f(5.4.2.\))324 1204 y Ff(seed)e
  197. XFl(is)i(a)f(p)q(oin)o(ter)h(to)f(a)g(seed)i(v)o(ector)f(to)g(b)q(e)g(used)g
  198. X(to)g(seed)g(the)g(RNG.)f(\(See)h(Section)262 1254 y(5.4.4.\))324
  199. X1303 y Ff(count1)f Fl(and)i Ff(count2)e Fl(determine)i(the)h(n)o(um)o(b)q(er)
  200. Xe(of)g(initial)f(v)n(alues)h(to)h(b)q(e)g(generated)262 1353
  201. Xy(b)o(y)e(the)i(RNG)e(and)g(then)i(discarded,)f(according)g(to)g(the)h(form)o
  202. X(ula:)324 1453 y(n)o(um)o(b)q(er)e(to)h(discard)g(=)g Ff(count1)21
  203. Xb(+)g(BILLION*count2)p Fl(,)324 1553 y(where)10 b Ff(BILLION)e
  204. XFl(is)i(de\014ned)g(in)f(`)p Ff(mrandom.h)p Fl(')e(as)j(the)g(decimal)e
  205. X(constan)o(t)i(1000000000.)324 1602 y Ff(bufsize)19 b Fl(is)i(the)g(size)h
  206. X(of)e(the)i(RNG's)e(main)f(bu\013er.)40 b(A)21 b(non-p)q(ositiv)o(e)f(v)n
  207. X(alue)g(of)262 1652 y Ff(bufsize)d Fl(will)g(b)q(e)i(in)o(terpreted)h(as)f(a)
  208. Xg(v)n(alue)f(of)g(1.)32 b(\(See)19 b(Section)g(5.4.2)e(for)i(more)e(in-)262
  209. X1702 y(formation)11 b(on)j(bu\013ering.\))324 1752 y Ff(kill_rng)f
  210. XFl(destro)o(ys)j(the)f(RNG,)f(making)e(it)j(in)o(v)n(alid)e(for)h(use.)22
  211. Xb(This)15 b(pro)q(cedure)h(de-)262 1802 y(allo)q(cates)11 b(the)h(space)h
  212. X(used)f(b)o(y)f(the)h(RNG,)f(and)g(should)g(therefore)i(b)q(e)f(used)h(to)e
  213. X(kill)f(RNGs)262 1851 y(whic)o(h)j(will)g(no)g(longer)h(b)q(e)h(used.)324
  214. X1901 y(Do)e Fc(not)i Fl(use)f(an)g Ff(RNGdata)f Fl(p)q(oin)o(ter)h(whic)o(h)g
  215. X(p)q(oin)o(ts)g(to)g(an)g(activ)o(e)g(RNG)f(to)h(store)h(the)262
  216. X1951 y(return)g(v)n(alue)e(of)g Ff(init_rng)p Fl(.)j(In)e(order)h(to)f
  217. X(initialize)e(an)i(RNG,)e(y)o(ou)i(should)f(either:)324 2034
  218. Xy Fe(\017)20 b Fl(Declare)15 b(a)f(new)h Ff(RNGdata)e Fl(p)q(oin)o(ter,)h
  219. X(and)g(then)h(use)g(it)f(to)g(store)h(the)g(return)g(v)n(alue)365
  220. X2084 y(of)f Ff(init_rng)p Fl(,)d(as)j(sho)o(wn)g(in)g(Figure)g(1.)324
  221. X2167 y Fe(\017)20 b Fl(Use)12 b Ff(kill_rng)c Fl(to)i(de-initialize)f(an)i
  222. XFf(RNGdata)d Fl(p)q(oin)o(ter)j(whic)o(h)f(p)q(oin)o(ts)g(to)g(an)h(activ)o
  223. X(e)365 2217 y(RNG,)h(and)h(then)g(use)h(that)f(p)q(oin)o(ter)g(to)f(store)i
  224. X(to)f(the)g(return)h(v)n(alue)f(of)f Ff(init_rng)p Fl(,)365
  225. X2267 y(as)19 b(sho)o(wn)g(in)f(Figure)g(2.)32 b(Figure)19 b(3)f(sho)o(ws)h
  226. X(ho)o(w)f(an)h(RNG)f(should)g Fc(not)h Fl(b)q(e)g(re-)365 2316
  227. Xy(initialized.)p eop
  228. X%%Page: 7 10
  229. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)645
  230. Xb Fl(7)324 465 y Ff(RNGdata)20 b(*rng;)324 515 y(long)h(seed[1];)324
  231. X615 y(rng=init_rng\(2,)d(0,)k(seed,)f(10000,)f(0,)i(8192\);)597
  232. X706 y Fl(Figure)14 b(1:)k(Prop)q(er)d(initialization)c(of)i(an)h(RNG)324
  233. X1121 y Ff(RNGdata)20 b(*myrng;)324 1171 y(long)h(seed[1];)324
  234. X1271 y(seed[0]=12345;)324 1320 y(myrng=init_rng\(2)o(,)e(0,)i(seed,)g(10000,)
  235. Xg(0,)g(8192\);)324 1370 y(kill_rng\(myrng\);)324 1420 y(myrng=init_rng\(3)o
  236. X(,)e(0,)i(seed,)g(5000,)g(0,)g(2048\);)573 1511 y Fl(Figure)14
  237. Xb(2:)j(Prop)q(er)f(re-initialization)11 b(of)i(an)h(RNG)324
  238. X1926 y Ff(RNGdata)20 b(*myrng;)324 1976 y(long)h(seed[1];)324
  239. X2076 y(seed[0]=12345;)324 2126 y(myrng=init_rng\(2)o(,)e(0,)i(seed,)g(10000,)
  240. Xg(0,)g(8192\);)324 2176 y(myrng=init_rng\(3)o(,)e(0,)i(seed,)g(5000,)g(0,)g
  241. X(2048\);)551 2267 y Fl(Figure)14 b(3:)j(Improp)q(er)d(re-initialization)d(of)
  242. Xj(an)f(RNG)p eop
  243. X%%Page: 8 11
  244. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)645
  245. Xb Fl(8)262 307 y Fh(5.4.2)47 b(Pro)q(cedures)14 b(for)h(Generating)e
  246. X(Pseudorandom)g(Num)o(b)q(ers)262 384 y Fl(An)g(initialized)e(RNG)h(can)h(b)q
  247. X(e)h(used)g(to)f(generate)h(pseudorandom)e(n)o(um)o(b)q(ers)h(b)o(y)f(using)h
  248. X(a)262 434 y(v)n(ariet)o(y)g(of)g(routines)i(describ)q(ed)g(in)f(this)g
  249. X(section.)324 483 y(Routines)g(are)g(pro)o(vided)g(for)f(pro)q(ducing)h
  250. X(generates)i(of)d(four)h(t)o(yp)q(es:)324 572 y Fe(\017)20
  251. Xb Fl(double)14 b(precision)g(\015oating)f(p)q(oin)o(t)h(generates)h(in)f(the)
  252. Xg(range)g([0,1\))324 653 y Fe(\017)20 b Fl(single)14 b(precision)g
  253. X(\015oating)f(p)q(oin)o(t)g(generates)j(in)d(the)i(range)f([0,1\))324
  254. X735 y Fe(\017)20 b Fl(long)c(in)o(teger)i(generates)g(in)e(the)i(range)f(0)p
  255. XFg(::r)11 b Fe(\000)g Fl(1,)17 b(where)h(r)f(is)g(the)h(range)f(of)f(the)365
  256. X785 y(RNG)d(b)q(eing)h(used)h(to)f(pro)q(duce)h(generates)324
  257. X867 y Fe(\017)20 b Fl(long)9 b(in)o(teger)g(generates)i(in)e(the)h(range)f(0)
  258. Xp Fg(::)p Ff(m)p Fe(\000)p Fl(1,)g(for)g(an)o(y)g(1)i Fe(\024)h
  259. XFf(m)f Fg(<)h Ff(range)p 1520 867 14 2 v 14 w(rng)p Fl(\()p
  260. XFf(rng)p Fl(\))324 955 y(Note)e(that)g(although)e(b)q(oth)i(single)f(and)h
  261. X(double)g(precision)g(\015oats)f(can)h(b)q(e)g(returned)i(b)o(y)262
  262. X1005 y(the)h(generate-pro)q(ducing)h(routines,)f(the)h(actual)e(precision)h
  263. X(of)f(the)i(generates)g(pro)q(duced)262 1054 y(is)f(determined)g(b)o(y)g(the)
  264. Xg(precision)h(of)e(the)i(underlying)f(generator)h(b)q(eing)f(used.)19
  265. Xb(In)13 b(other)262 1104 y(w)o(ords,)j(the)h(di\013erence)h(b)q(et)o(w)o(een)
  266. Xg(routines)f(whic)o(h)f(return)h(generates)h(of)e(t)o(yp)q(e)h
  267. XFf(double)262 1154 y Fl(and)f(those)i(whic)o(h)e(return)i(generates)h(of)d(t)
  268. Xo(yp)q(e)h Ff(float)f Fl(is)h(merely)f(in)g(the)i(\\pac)o(k)n(aging")262
  269. X1204 y(of)i(the)h(generates,)i(not)e(in)f(the)i(precision)f(they)g(pro)o
  270. X(vide.)38 b(Information)18 b(ab)q(out)j(the)262 1254 y(precision)12
  271. Xb(of)g(the)h(RNGs)f(curren)o(tly)i(installed)e(in)g(the)h(pac)o(k)n(age)f(is)
  272. Xg(in)g(App)q(endix)h(B;)g(suc)o(h)262 1303 y(information)h(can)j(also)f(b)q
  273. X(e)i(obtained)f(at)g(run-time)f(through)h(the)g Ff(range_rng)e
  274. XFl(routine)262 1353 y(\(see)k(Section)g(5.4.7\).)29 b(The)19
  275. Xb(curren)o(t)h(v)o(ersion)e(of)g(the)g(pac)o(k)n(age)g(only)g(supp)q(orts)h
  276. X(RNGs)262 1403 y(with)13 b(precisions)i(of)e(no)h(more)f(than)g(32)h(bits.)
  277. X324 1453 y(Both)c(bu\013ered)i(and)e(un)o(bu\013ered)i(routines)f(are)f(pro)o
  278. X(vided.)17 b(Un)o(bu\013ered)12 b(routines)e(call)262 1503
  279. Xy(the)i(underlying)f(RNG)f(only)h(as)h(man)o(y)d(times)i(as)g(are)h(needed)h
  280. X(to)f(pro)q(duce)g(the)g(requested)262 1553 y(n)o(um)o(b)q(er)j(of)g
  281. X(generates,)j(while)e(bu\013ered)i(routines)e(main)o(tain)e(bu\013ers)j(of)f
  282. X(generates,)i(so)262 1602 y(that)13 b(generates)i(ma)o(y)d(b)q(e)i(pro)q
  283. X(duced)h(e\016cien)o(tly)f(ev)o(en)g(when)g(requested)i(in)d(small)e(quan-)
  284. X262 1652 y(tities.)24 b(Roughly)m(,)14 b(bu\013ered)k(routines)e(are)h
  285. X(preferable)g(when)f(generates)i(are)e(requested)262 1702 y(one)h(at)g(a)h
  286. X(time)e(or)h(in)g(small)e(quan)o(tities,)j(while)f(un)o(bu\013ered)i
  287. X(routines)f(are)g(preferable)262 1752 y(when)g(generates)i(are)e(requested)i
  288. X(in)e(large)g(quan)o(tities.)30 b(Some)17 b(other)i(di\013erences)h(b)q(e-)
  289. X262 1802 y(t)o(w)o(een)15 b(bu\013ered)g(and)g(un)o(bu\013ered)g(routines)g
  290. X(are)g(discussed)h(later)f(in)f(this)g(section.)20 b(The)262
  291. X1851 y(size)g(of)e(the)i(bu\013er)g(used)h(b)o(y)e(an)g(RNG)f(is)i
  292. X(determined)f(at)g(the)h(time)e(of)h(the)g(RNG's)262 1901 y(initialization;)
  293. X10 b(e\013ectiv)o(e)15 b(bu\013er)g(sizes)g(will)e(v)n(ary)g(from)f
  294. X(application)h(to)g(application.)324 1951 y(The)d(name)f(of)g(a)h(routine)g
  295. X(denotes)h(the)g(t)o(yp)q(e)f(of)g(the)g(v)n(alue)f(whic)o(h)h(the)h(routine)
  296. Xf(returns)262 2001 y(and)k(whether)i(the)f(routine)g(is)f(bu\013ered)i(or)f
  297. X(un)o(bu\013ered.)21 b(The)15 b(\014rst)h(letter)f(of)f(a)g(routine)262
  298. X2051 y(denotes)g(the)g(t)o(yp)q(e)g(of)e(v)n(alue)h(whic)o(h)g(it)g(returns:)
  299. X19 b(\\d")13 b(for)g(double)g(precision)h(and)f(\\f)s(")g(for)262
  300. X2100 y(single)e(precision)h(\015oating)e(p)q(oin)o(t)i(in)f(the)h(range)g
  301. X([0,1\);)e(\\l")h(for)g(long)g(in)o(teger)h(in)f(the)h(range)262
  302. X2150 y(0..\()p Ff(range_rng\()o(rng\))p Fl(-)o(1\),)f(and)j(\\b")g(for)f(bit)
  303. Xh(\(either)h(a)f(0)g(or)g(a)g(1\).)19 b(If)14 b(the)g(second)i(letter)262
  304. X2200 y(of)d(the)i(routine's)f(name)f(is)i(an)f(\\x",)f(then)i(the)g(routine)f
  305. X(is)g(un)o(bu\013ered.)21 b(Otherwise,)15 b(the)262 2250 y(routine)f(is)f
  306. X(bu\013ered.)324 2300 y(F)m(or)h(con)o(v)o(enience)j(in)d(user)i(programming)
  307. Xo(,)c(w)o(e)j(also)g(pro)o(vide)f(a)h(n)o(um)o(b)q(er)f(of)g(macros)262
  308. X2350 y(that)c(supply)g(default)f(parameter)h(v)n(alues.)17
  309. Xb(The)10 b(last)g(t)o(w)o(o)g(letters)h(of)f(all)f(our)h(fundamen)o(tal)262
  310. X2399 y(routines)i(is)h(\\rv".)k(This)12 b(means)f(that)i(they)g(m)o(ust)e(b)q
  311. X(e)i(pro)o(vided)f(with)g(b)q(oth)g(a)g(p)q(oin)o(ter)h(to)262
  312. X2449 y(an)f Ff(RNGdata)f Fl(structure)k(and)d(a)g(v)o(ector)h(to)g(\014ll)e
  313. X(with)i(generates)h(from)d(the)i(RNG.)e(Macros)p eop
  314. X%%Page: 9 12
  315. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)645
  316. Xb Fl(9)262 307 y(whose)19 b(names)f(do)h(not)f(con)o(tain)h(an)g(\\r")f(ha)o
  317. X(v)o(e)h(the)g Ff(RNGdata)f Fl(p)q(oin)o(ter)h(omitted)e(from)262
  318. X357 y(their)c(parameter)g(list;)g(they)h(use)g(the)g(most-recen)o(tly)f
  319. X(initialized)f(or)i(restarted)h(RNG)e(to)262 407 y(pro)q(duce)j(generates.)22
  320. Xb(Macros)16 b(whose)f(names)f(do)h(not)f(con)o(tain)h(a)f(\\v")h(ha)o(v)o(e)f
  321. X(the)i(v)o(ector)262 457 y(and)f(n)o(um)o(b)q(er)g(of)g(generates)i(omitted)e
  322. X(from)f(their)i(parameter)f(list;)h(they)g(pro)q(duce)h(and)262
  323. X506 y(return)e(a)e(single)h(generate.)324 556 y(All)j(generating)h(routines)h
  324. X(ab)q(ort)f(with)f(a)h(message)g(to)g Ff(stderr)e Fl(if)h(called)h(with)g(an)
  325. X262 606 y(in)o(v)n(alid)11 b Ff(RNGdata)i Fl(p)q(oin)o(ter.)262
  326. X706 y Fh(Bu\013ering)324 805 y Fl(The)18 b(op)q(eration)g(of)g(the)g
  327. X(bu\013ered)i(routines)e(and)g(their)g(in)o(teraction)g(with)g(the)h(un-)262
  328. X855 y(bu\013ered)13 b(routines)g(requires)h(some)e(elab)q(oration.)k(Eac)o(h)
  329. Xd(RNG)f(main)o(tains)d(t)o(w)o(o)j(separate)262 905 y(bu\013ers:)28
  330. Xb(one)18 b(for)g(bu\013ering)h(bit)e(v)n(alues)h(\(the)h(\\bit)f
  331. X(bu\013er"\),)i(and)e(one)g(for)g(bu\013ering)262 955 y(all)e(other)h(v)n
  332. X(alues)g(\(the)h(\\main)d(bu\013er"\).)29 b(The)18 b(size)g(of)f(the)g(main)f
  333. X(bu\013er)i(of)e(an)h(RNG)262 1005 y(is)e(determined)g(at)g(the)h(time)e(of)h
  334. X(the)h(RNG's)e(initialization,)f(while)h(the)i(size)g(of)f(the)h(bit)262
  335. X1054 y(bu\013er)e(is)g(curren)o(tly)h(\014xed)f(at)g(32)f(bits.)324
  336. X1104 y(Consider)e(a)f(freshly-initialized)f(RNG)h(with)g(a)g(main)f(bu\013er)
  337. Xi(size)h(of)e(1000.)15 b(A)c(request)262 1154 y(is)k(made)g(for)h(a)g(single)
  338. Xf(generate)j(of)d(t)o(yp)q(e)h Ff(long)p Fl(.)24 b(The)16 b(RNG's)g(bu\013er)
  339. Xh(gets)f(\014lled)g(with)262 1204 y(1000)i(generates,)23 b(and)d(the)g
  340. X(\014rst)h(suc)o(h)f(generate)i(is)d(returned)j(to)e(the)g(user.)37
  341. Xb(So)20 b(the)262 1254 y(bu\013er)d(no)o(w)f(con)o(tains)g(999)g(generates.)
  342. X27 b(If)16 b(another)h(generate)h(of)e(t)o(yp)q(e)h Ff(long)p
  343. XFl(,)e Ff(double)p Fl(,)262 1303 y(or)g Ff(float)p Fl(,)g(is)g(requested,)j
  344. X(a)d(generate)i(will)d(b)q(e)i(pulled)g(from)e(the)i(bu\013er)g(and)g
  345. X(returned)262 1353 y(to)g(the)h(user)g(after)g(b)q(eing)f(con)o(v)o(erted)h
  346. X(to)g(the)f(prop)q(er)i(t)o(yp)q(e.)26 b(If)16 b(the)g(user)i(con)o(tin)o
  347. X(ues)f(to)262 1403 y(request)f(generates)g(in)f(this)f(w)o(a)o(y)g(and)h(the)
  348. Xg(main)e(bu\013er)j(b)q(ecomes)f(depleted,)g(it)g(will)e(b)q(e)262
  349. X1453 y(\014lled)g(again)g(with)g(1000)g(generates,)i(and)f(so)g(on.)324
  350. X1503 y(The)i(un)o(bu\013ered)i(routines)f(do)e(not)h(in)o(terfere)i(with)d
  351. X(either)i(of)f(the)g(RNG's)g(bu\013ers.)262 1553 y(Again,)e(consider)i(our)g
  352. X(RNG,)e(with)h(its)g(bu\013er)i(\014lled)e(with)g(1000)f(generates.)25
  353. Xb(The)16 b(user)262 1602 y(no)o(w)h(mak)o(es)g(a)h(request)i(for)d(a)h
  354. X(single)g(un)o(bu\013ered)h(generate.)32 b(The)19 b(underlying)e(RNG)262
  355. X1652 y(will)12 b(then)j(b)q(e)g(called)f(once,)h(returning)f(a)g(single)g
  356. X(generate,)h(lea)o(ving)e(our)i(bu\013er)g(of)f(1000)262 1702
  357. Xy(generates)g(un)o(touc)o(hed,)f(and)f(still)g(ready)h(to)f(b)q(e)i(accessed)
  358. Xh(b)o(y)d(the)h(bu\013ered)h(routines.)k(If,)262 1752 y(in)d(a)g(particular)h
  359. X(application,)e(it)h(is)h(necessary)i(to)d(alw)o(a)o(ys)g(use)i(consecutiv)o
  360. X(e)g(generates)262 1802 y(from)c(an)i(RNG,)f(then)h(that)h(RNG)e(should)h
  361. X(alw)o(a)o(ys)f(b)q(e)i(called)f Fc(either)f Fl(with)h(bu\013ered)i(or)262
  362. X1851 y(un)o(bu\013ered)e(routines,)f(but)g(not)g(with)f(a)h(com)o(bination)d
  363. X(of)j(b)q(oth.)324 1901 y(The)e(bit)f(bu\013er)h(of)f(an)g(RNG)f(op)q(erates)
  364. Xj(similarly)8 b(to)j(the)h(main)e(bu\013er,)i(with)f(one)h(k)o(ey)262
  365. X1951 y(di\013erence:)23 b(the)16 b(bit)f(bu\013er)i(is)e(\014lled)h(b)o(y)f
  366. X(sequen)o(tially)g(retrieving)h(generates)h(from)d(the)262
  367. X2001 y(main)9 b(bu\013er.)18 b(Once)13 b(again,)d(consider)i(our)f(RNG,)f
  368. X(with)i(its)f(bu\013er)h(\014lled)f(with)g(1000)g(gen-)262
  369. X2051 y(erates,)i(and)g(with)f(its)g(bit)h(bu\013er)g(empt)o(y)m(.)j(A)d
  370. X(single)f(bit)g(is)h(then)g(requested.)20 b(Thirt)o(y-t)o(w)o(o)262
  371. X2100 y(generates)15 b(will)d(b)q(e)i(pulled)g(from)e(the)i(main)d(bu\013er,)k
  372. X(transformed)e(in)o(to)g(thirt)o(y-t)o(w)o(o)g(one-)262 2150
  373. Xy(bit)f(0-1)h(v)n(alues,)f(then)i(stored)g(in)e(the)i(bit)e(bu\013er.)19
  374. Xb(\(F)m(or)13 b(users)h(who)f(are)h(more)e(concerned)262 2200
  375. Xy(with)k(sp)q(eed)i(than)f(accuracy)m(,)h(w)o(e)f(also)f(pro)o(vide)h(a)f
  376. X(\\fast")g(bit-bu\013er)i(call,)e(in)g(whic)o(h)h(a)262 2250
  377. Xy(single)f(32-bit)f(generate)j(from)d(the)i(main)d(bu\013er)k(is)e
  378. X(transformed)g(in)o(to)g(thirt)o(y-t)o(w)o(o)f(0-1)262 2300
  379. Xy(v)n(ariates.)i(See)e(the)g(descriptions)g(of)e Ff(bxrandom_f)f
  380. XFl(and)h Ff(brandom_f)p Fl(,)f(b)q(elo)o(w.\))p eop
  381. X%%Page: 10 13
  382. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)624
  383. Xb Fl(10)262 307 y Fh(Un)o(bu\013ered)12 b(and)j(bu\013ered)f(calling)g(pro)q
  384. X(cedures)324 407 y Ff(double)20 b(dxrandomrv\(rng,)f(n,)i(v\))324
  385. X457 y(double)f(drandomrv\(rng,)f(n,)j(v\))324 506 y(RNGdata)e(*rng;)324
  386. X556 y(long)h(n;)324 606 y(double)f(v[];)324 706 y(float)h(fxrandomrv\(rng,)d
  387. X(n,)k(v\))324 756 y(float)f(frandomrv\(rng,)d(n,)k(v\))324
  388. X805 y(RNGdata)e(*rng;)324 855 y(long)h(n;)324 905 y(float)g(v[];)324
  389. X1005 y(long)g(lxrandomrv\(rng,)d(n,)k(v\))324 1054 y(long)f(lrandomrv\(rng,)e
  390. X(n,)i(v\))324 1104 y(RNGdata)f(*rng;)324 1154 y(long)h(n;)324
  391. X1204 y(long)g(v[];)324 1303 y(int)g(bxrandomrv\(rng,)e(n,)i(v\))324
  392. X1353 y(int)g(brandomrv\(rng,)e(n,)i(v\))324 1403 y(RNGdata)f(*rng;)324
  393. X1453 y(long)h(n;)324 1503 y(int)g(v[];)324 1602 y(int)g(bxrandomrv_f\(rng,)d
  394. X(n,)k(v\))324 1652 y(int)f(brandomrv_f\(rng,)d(n,)k(v\))324
  395. X1702 y(RNGdata)e(*rng;)324 1752 y(long)h(n;)324 1802 y(double)f(v[];)324
  396. X1901 y Fl(These)d(routines)g(\014ll)e(the)i(v)o(ector)g Ff(v)f
  397. XFl(with)g Ff(n)g Fl(generates)i(from)d Ff(rng)p Fl(,)g(and)i(return)g(the)262
  398. X1951 y(\014rst)d(generate)h(pro)q(duced)h(\(i.e.)h Ff(v[0])p
  399. XFl(\).)324 2001 y(If)10 b Ff(rng)g Fl(is)g(a)h(n)o(ull)e(p)q(oin)o(ter,)i
  400. X(then)g(the)h(most-recen)o(tly)e(initialized)f(or)i(restarted)h(RNG)e(is)262
  401. X2051 y(used)i(to)g(pro)q(duce)h(generates.)18 b(If)12 b Ff(n)f
  402. XFl(is)h(0,)f(then)i(the)f Ff(v)f Fl(parameter)h(need)g(not)g(b)q(e)g(pro)o
  403. X(vided,)262 2100 y(and)h(a)h(single)f(generate)j(is)d(pro)q(duced)i(and)f
  404. X(returned.)324 2150 y Ff(bxrandomrv)f Fl(uses)j(one)f(generate)i(from)c
  405. XFf(rng)h Fl(to)h(generate)i(eac)o(h)e(bit.)21 b(This)15 b(routine)262
  406. X2200 y(is)e(slo)o(w)o(er)h(than)g Ff(bxrandomrv_f)p Fl(,)d(but)j(returns)h
  407. X(bits)f(of)g(higher)g(qualit)o(y)m(.)324 2250 y Ff(bxrandomrv)p
  408. X547 2250 14 2 v 13 w(f)i Fl(uses)i(eac)o(h)f(generate)g(from)e
  409. XFf(rng)g Fl(to)h(pro)q(duce)i(32)e(bits.)25 b(Therefore,)262
  410. X2300 y(requests)14 b(for)e(bits)g(in)g(other)h(than)f(m)o(ultiples)e(of)i(32)
  411. Xg(will)e(result)k(in)d(bits)i(from)d(the)j(stream)262 2350
  412. Xy(b)q(eing)i(\\lost")g(b)q(et)o(w)o(een)i(calls.)22 b(The)16
  413. Xb(routine)g(returns)h(-1)e(if)f(it)h(is)h(called)f(with)g(an)g(RNG)262
  414. X2399 y(whose)f(range)h(is)f(not)g(2)635 2384 y Fb(32)670 2399
  415. Xy Fl(.)19 b(This)14 b(routine)h(is)f(faster)h(than)f Ff(bxrandomrv)p
  416. XFl(,)e(but)i(w)o(e)h(do)f(not)262 2449 y(recommend)9 b(its)j(use,)g(since)g
  417. X(w)o(e)f(kno)o(w)g(of)g(no)g(one)g(who)g(has)h(rigorously)e(tested)j(suc)o(h)
  418. Xf(a)f(bit)p eop
  419. X%%Page: 11 14
  420. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)624
  421. Xb Fl(11)262 307 y(stream.)16 b(W)m(e)9 b(gain)g(con\014dence)j(in)e(our)g
  422. X(slo)o(w)o(er)g Ff(bxrandomrv)e Fl(bit)h(stream,)h(in)g(comparison,)262
  423. X357 y(ev)o(ery)i(time)f(the)h(underlying)g(generator)h(passes)g(a)f(test)h
  424. X(sensitiv)o(e)f(to)g(correlations)g(in)g(the)262 407 y(leading)k(digit)h(of)g
  425. X(its)g(\015oating)g(p)q(oin)o(t)g(output,)h(or)g(to)f(the)i(most)d
  426. X(signi\014can)o(t)h(bit)h(of)f(its)262 457 y(\014xed)d(p)q(oin)o(t)f(output.)
  427. X324 506 y Ff(brandomrv_f)p Fl(,)i(the)j(bu\013ered)h(v)o(ersion)f(of)e
  428. XFf(bxrandomrv_f)p Fl(,)g(do)q(es)i(not)f(exhibit)g(the)262
  429. X556 y(same)c(prop)q(ert)o(y)j(of)e(\\losing)f(bits")h(as)h(do)q(es)g
  430. XFf(bxrandomrv_f)p Fl(,)d(since)k(bits)e(whic)o(h)h(are)g(not)262
  431. X606 y(used)h(in)g(one)g(call)f(to)h Ff(brandomrv_f)d Fl(are)k(stored)f(in)g
  432. X(the)g(bit)g(bu\013er)h(and)f(are)g(a)o(v)n(ailable)262 656
  433. Xy(for)d(use)i(up)q(on)f(future)g(calls.)324 756 y Ff(int)21
  434. Xb(flush_rng\(rng\))324 805 y(RNGdata)f(*rng;)324 905 y Fl(Flushes)15
  435. Xb(b)q(oth)f(of)f(the)h(RNG's)f(bu\013ers.)262 1005 y Fh(Pro)q(cedure)h(for)h
  436. X(generating)e(in)o(tegers)g(in)i(a)h(restricted)d(range)324
  437. X1104 y Ff(long)21 b(mrandomrv\(rng,)e(m,)i(n,)g(v\))324 1154
  438. Xy(RNGdata)f(*rng;)324 1204 y(long)h(m,n,v[];)324 1303 y(mrandomrv)10
  439. Xb Fl(\014lls)i(the)g(v)o(ector)h Ff(v)f Fl(with)g Ff(n)g Fl(generates)h(in)f
  440. X(the)h(range)f(0)p Fg(::)p Ff(m)6 b Fe(\000)g Fl(1)k(using)i
  441. XFf(rng)p Fl(,)262 1353 y(where)18 b(1)e Fe(\024)h Ff(m)g Fe(\024)g
  442. XFf(range)p 672 1353 14 2 v 14 w(rng)p Fl(\()p Ff(rng)p Fl(\).)27
  443. Xb(If)17 b Ff(range)p 1044 1353 V 14 w(rng)p Fl(\()p Ff(rng)p
  444. XFl(\))f Fg(<)h Ff(m)p Fl(,)g(the)h(program)d(ab)q(orts)262
  445. X1403 y(with)e(an)h(error.)324 1453 y(The)c(algorithm)c(used)k(b)o(y)f
  446. XFf(mrandomrv)f Fl(to)h(\014ll)f Ff(v)h Fl(is)g(set)h(b)o(y)g
  447. XFf(init_rng)d Fl(or)i(b)o(y)g Ff(mralg_rng)p Fl(.)262 1503
  448. Xy(\(See)14 b(Section)h(5.4.1)d(and)i(Section)g(5.4.7.\))324
  449. X1553 y(Algorithm)i(0)i(is)g(Thom)o(b)q(orson's)f(un)o(biased)i(metho)q(d,)f
  450. X(whic)o(h)g(pro)q(duces)i(un)o(biased)262 1602 y(long)13 b(in)o(tegers)i(in)e
  451. X(the)i(range)f([0..)p Ff(m)p Fl(\).)k(The)c(algorithm)e(discards)j(an)o(y)e
  452. X(outputs)i(from)d Ff(rng)262 1652 y Fl(whic)o(h)j(are)i(larger)f(than)f
  453. XFg(r)d Fe(\000)f Fl(\()p Fg(r)h Fl(mo)q(d)e Ff(m)p Fl(\),)16
  454. Xb(where)h(r)f(is)g(equal)g(to)f Ff(range)p 1425 1652 V 15 w(rng\(rng\))p
  455. XFl(.)23 b(A)o(t)262 1702 y(w)o(orst,)15 b(this)g(co)q(de)h(will)e(discard)i
  456. X(\(on)f(long-term)e(a)o(v)o(erage\))j(at)f(most)f(one)h(v)n(alue)g(of)g(r)g
  457. X(for)262 1752 y(ev)o(ery)d(one)h(that)f(is)g(useful.)17 b(This)12
  458. Xb(w)o(orst)g(case)h(is)f(only)g(encoun)o(tered)i(for)d(extremely)h(large)262
  459. X1802 y Ff(m)p Fl(;)h(for)h(\014xed)g(and)g(mo)q(derate)g Ff(m)p
  460. XFl(,)f(this)h(co)q(de)h(will)d(rarely)j(discard)f(a)g(v)n(alue,)f(and)h(th)o
  461. X(us)g(will)262 1851 y(run)f(essen)o(tially)g(as)g(fast)f(as)h(algorithm)e(1.)
  462. X17 b(When)c(the)h(v)n(alue)e(of)g Ff(m)h Fl(c)o(hanges)g(on)g(eac)o(h)g(call)
  463. X262 1901 y(to)g Ff(mrandom)p Fl(,)f(ho)o(w)o(ev)o(er,)h(this)h(co)q(de)g(is)g
  464. X(slo)o(w)o(er)g(than)f(algorithm)e(1,)i(due)h(to)g(the)g(necessit)o(y)262
  465. X1951 y(of)f(recomputing)g Fg(r)d Fe(\000)f Fl(\()p Fg(r)k Fl(mo)q(d)d
  466. XFf(m)p Fl(\).)324 2001 y(The)15 b(program)e(ab)q(orts)i(with)f(an)g(error)i
  467. X(message)e(to)g Ff(stderr)f Fl(if)h Ff(rng)g Fl(is)g(b)q(eha)o(ving)h(so)262
  468. X2051 y(non-randomly)10 b(that)j(Algorithm)e(0)i(m)o(ust)f(mak)o(e)g(an)h
  469. X(excessiv)o(e)i(n)o(um)o(b)q(er)d(of)h(calls)f(to)h Ff(rng)262
  470. X2100 y Fl(in)g(order)i(to)e(pro)q(duce)i(the)g(requested)h(n)o(um)o(b)q(er)d
  471. X(of)g(generates.)324 2150 y(The)j(program)f(ab)q(orts)h(with)g(an)g(error)h
  472. X(to)f Ff(stderr)f Fl(if)g Ff(mrandomrv)f Fl(is)i(ask)o(ed)h(to)f(use)262
  473. X2200 y(Algorithm)11 b(0)j(with)f(a)h(v)n(alue)f(of)g Ff(m)h
  474. XFl(for)g(whic)o(h)f Ff(m)f Fg(>)f Ff(range)p 1187 2200 V 15
  475. Xw(rng)p Fl(\()p Ff(rng)p Fl(\))o(.)324 2300 y(Algorithm)j(1)j(is)f(the)i
  476. X(standard)f Ff(\(long\)\(m*dxrandom)o(r\(rng)o(\)\))p Fl(.)24
  477. Xb(This)16 b(algorithm)262 2350 y(ma)o(y)9 b(b)q(e)j(biased:)17
  478. Xb(for)12 b(large)f Ff(m)p Fl(,)g(some)g(results)i(ma)o(y)c(b)q(e)j(b)q(e)h
  479. X(more)d(lik)o(ely)g(than)i(others.)18 b(The)262 2399 y(bias)d(is)397
  480. X2383 y Fa(r)s Fb(mo)q(d)s Ff(m)p 397 2390 105 2 v 439 2414
  481. Xa(m)507 2399 y Fl(,)h(whic)o(h)g(is)f(upp)q(er-b)q(ounded)i(b)o(y)f(0.1\045)e
  482. X(if)h Ff(m)h Fl(is)f(less)h(than)g(a)g(milli)o(on)d(and)262
  483. X2449 y(the)h(range)g(r)g(of)g Ff(rng)f Fl(is)g(at)h(least)g(a)g(billion.)p
  484. Xeop
  485. X%%Page: 12 15
  486. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)624
  487. Xb Fl(12)324 307 y(W)m(e)10 b(do)h(not)g(supp)q(ort,)h(and)f(indeed)g(w)o(e)h
  488. X(activ)o(ely)e(discourage,)i(generating)f(restricted-)262 357
  489. Xy(range)j(in)o(tegers)i(with)e Ff(lrandomr\(rng\)\045m)p Fl(.)i(Man)o(y)f
  490. X(RNGs)f(ha)o(v)o(e)g(p)q(o)q(or)h(b)q(eha)o(vior)f(under)262
  491. X407 y(this)h(transformation,)e(most)h(noticeably)h(when)h Ff(m)e
  492. XFl(is)i(a)e(p)q(o)o(w)o(er)i(of)f(2.)21 b(When)16 b Ff(m)f
  493. XFl(is)g(not)g(a)262 457 y(p)q(o)o(w)o(er)d(of)g(2,)h(\014xed-p)q(oin)o(t)f
  494. X(division)f(required)j(b)o(y)e(an)h(\\)p Ff(\045)p Fl(")e(op)q(eration)i(is)f
  495. X(time-consuming)262 506 y(on)h(man)o(y)f(w)o(orkstations.)262
  496. X606 y Fh(NOTES)324 656 y Fl(The)k Ff(mrandomrv)d Fl(pro)q(cedure)18
  497. Xb(is)d(capable)g(of)g(generating)h(long)e(in)o(tegers)j(in)e(the)h(full)262
  498. X706 y(range)c(of)g(an)o(y)g(RNG)g(for)h(whic)o(h)f(1)f Fe(\024)h
  499. XFf(range)p 972 706 14 2 v 15 w(rng)p Fl(\()p Ff(rng)p Fl(\))e
  500. XFe(\024)i Fl(2)1223 691 y Fb(32)1258 706 y Fl(.)18 b(In)12
  501. Xb(order)i(to)e(accomplish)262 756 y(this,)g(with)h(the)g(parameter)g
  502. XFf(m)f Fl(a)h(signed)g(long)f(in)o(teger,)h(the)h(follo)o(wing)c(mapping)g
  503. X(is)j(used:)262 847 y(Range\()p Ff(mrandom\(m\))p Fl(\))e(=)j(0)p
  504. XFg(::)p Ff(m)8 b Fe(\000)i Fl(1)177 b(if)13 b(1)e Fe(\024)h
  505. XFf(m)g Fg(<)f Fl(2)1212 832 y Fb(31)685 897 y Fl(0)p Fg(::)p
  506. XFl(2)751 882 y Fb(32)794 897 y Fe(\000)f Fl(1)143 b(if)13 b
  507. XFf(m)e Fl(=)h(0)685 946 y(0)p Fg(::)p Fl(\(2)767 931 y Fb(31)810
  508. X946 y Fe(\000)e Ff(m)f Fe(\000)g Fl(1\))39 b(if)13 b Fe(\000)p
  509. XFl(2)1091 931 y Fb(31)1138 946 y Fe(\024)f Ff(m)f Fg(<)h Fl(0)324
  510. X1038 y(Macros)18 b(are)f(de\014ned)h(for)f(easy)h(calling)d(of)i
  511. XFf(mrandomrv)e Fl(with)i(v)n(arious)f(default)h(pa-)262 1088
  512. Xy(rameters.)h(See)c(Section)f(5.4.2)e(for)i(the)h(naming)d(con)o(v)o(en)o
  513. X(tions)i(follo)o(w)o(ed)e(b)o(y)i(the)h(macros.)262 1195 y
  514. XFh(5.4.3)47 b(Sa)o(ving)15 b(and)g(restarting)e(RNGs)262 1272
  515. Xy Fl(RNGs)h(ma)o(y)f(b)q(e)j(sa)o(v)o(ed)f(to)g(disk)f(\014les)i(in)e(a)h(h)o
  516. X(uman-readable)e(ASCI)q(I)j(format)d(and)i(later)262 1322 y(restarted.)27
  517. Xb(RNG)16 b(bu\013ers)i(are)f(not)g(sa)o(v)o(ed,)f(and)h(therefore)h(all)d
  518. X(restarted)k(RNGs)d(ha)o(v)o(e)262 1372 y(empt)o(y)f(bu\013ers,)k(and)d(an)o
  519. X(y)h(data)f(remaining)f(in)h(an)h(RNG's)f(bu\013er)i(at)e(the)i(time)d(of)i
  520. X(its)262 1422 y(state-sa)o(v)o(e)d(will)f Fc(not)h Fl(b)q(e)g(reconstructed.)
  521. X324 1521 y Ff(int)21 b(save_rng\(rng,)e(filename\))324 1571
  522. Xy(RNGdata)h(*rng;)324 1621 y(char)h(*filename;)324 1720 y(RNGdata)f
  523. X(*restart_rng\(filen)o(ame\))324 1770 y(char)h(*filename;)324
  524. X1870 y(save_rng)12 b Fl(sa)o(v)o(es)i Ff(rng)g Fl(to)f(the)i(ASCI)q(I)f
  525. X(\014le)g(named)f Ff(filename)p Fl(.)324 1920 y Ff(restart_rng)7
  526. Xb Fl(restarts)k(an)e(RNG)f(from)g(a)h(previously)g(sa)o(v)o(ed)g
  527. X(state\014le.)18 b(The)9 b(restarted)262 1969 y(RNG)g(will)f(b)q(egin)i
  528. X(where)i(the)e(sa)o(v)o(ed)g(RNG)g(\\left)f(o\013.")17 b(As)10
  529. Xb(with)g Ff(init_rng)p Fl(,)e(the)j Ff(RNGdata)262 2019 y Fl(p)q(oin)o(ter)f
  530. X(used)h(to)e(store)i(the)g(restarted)h(RNG)d Fc(must)h Fl(b)q(e)h(either)f(a)
  531. Xg(freshly)g(declared)h(p)q(oin)o(ter)262 2069 y(or)i(a)h(p)q(oin)o(ter)g(to)g
  532. X(a)f(freshly)h(killed)f(RNG)g(\(see)j(Section)e(5.4.1\).)324
  533. X2119 y(RNGs)e(ma)o(y)f(store)j(their)f(state)g(and)g(seed)h(v)o(ectors)g(in)e
  534. X(an)o(y)h(of)f(a)g(n)o(um)o(b)q(er)g(of)h(formats,)262 2169
  535. Xy(and)e(this)g(is)g(re\015ected)i(in)e(the)h(format)d(of)i(the)g(state)h
  536. X(\014le.)17 b(Figure)12 b(4)f(sho)o(ws)g(a)g(sample)f(state)262
  537. X2219 y(\014le)g(of)g(an)g(RNG)g(using)h(the)g(Kn)o(uth/Ben)o(tley)g
  538. X(lagged-Fib)q(onnacci)f(generator)h(prand)g(\(see)262 2268
  539. Xy(App)q(endix)17 b(B\),)h(whic)o(h)e(stores)j(its)e(state)g(and)g(seeds)i(as)
  540. Xe(32-bit)f Ff(long)21 b(int)p Fl(s.)27 b(Figure)17 b(5)262
  541. X2318 y(sho)o(ws)11 b(a)f(sample)g(state)i(\014le)f(of)f(an)h(RNG)f(using)h
  542. X(4.3bsd)f Ff(nrand48)p Fl(,)g(whic)o(h)h(stores)h(its)f(state)262
  543. X2368 y(and)i(seeds)j(as)e(16-bit)f Ff(int)p Fl(s.)324 2418
  544. Xy(A)g(few)h(examples)f(of)g(ho)o(w)g(to)g(sa)o(v)o(e)h(and)f(restart)i(RNGs)f
  545. X(are)g(displa)o(y)o(ed)f(in)g(Figure)g(6.)p eop
  546. X%%Page: 13 16
  547. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)624
  548. Xb Fl(13)324 307 y Ff(RNG)21 b(statefile)f(for)h(algorithm)f(2,)h
  549. X(\(Knuth/Bentley)e(prand:)i(lagged)324 356 y(Fibbonacci\))324
  550. X406 y(Buffer)f(size)h(=)h(1024)f(bytes)324 456 y(Initial)f(seed)h(table)g(=)
  551. X389 506 y(00000927)324 556 y(Number)f(of)i(calls)e(to)i(underlying)e(RNG)h
  552. X(after)g(seeding)f(=)h(0)h(billion)324 605 y(+)f(2000)324 655
  553. Xy(Next)g(value)g(in)g(this)g(pseudorandom)e(sequence)h(=)i(0b64d0ea)324
  554. X705 y(This)f(RNG)g(returns)f(every)h(1)h(generates)324 755
  555. Xy(This)f(RNG)g(uses)g(mrandom)f(algorithm)g(0)324 805 y(RNG)h(state)g(table)f
  556. X(=)389 855 y(0911c27a)g(10641ca0)g(2ba00807)h(1aabed0a)389
  557. X904 y(273ff367)f(1ab88564)g(2ae76a9e)h(2a7e6bc0)389 954 y(35c7568e)f
  558. X(201b6b04)g(3ad90695)h(303208b2)389 1004 y(1e718896)f(054c9886)g(00e8c93f)h
  559. X(130a41cb)389 1054 y(11de97bf)f(0da54e15)g(2f4fcca0)h(0ebb1f70)389
  560. X1104 y(01c195c3)f(3283980e)g(37dee108)h(0893a89b)389 1153 y(326849b0)f
  561. X(167bb45e)g(19cc9765)h(33d97b51)389 1203 y(36b425d1)f(35704e34)g(29a638ca)h
  562. X(280a086f)389 1253 y(11dfa5d6)f(14dcbcc4)g(2610bdf4)h(02534109)389
  563. X1303 y(2817daf4)f(0bcf76ab)g(19b0a07d)h(0eebf7f6)389 1353 y(113c003e)f
  564. X(31b996b0)g(12bab234)h(05eddb36)389 1402 y(1ed71381)f(377742a3)g(3878e079)h
  565. X(2668c922)389 1452 y(22cc8033)f(22368c85)g(18e960ea)h(2002b06f)389
  566. X1502 y(22ff23e8)f(251187dc)g(340c3dcd)h(00000023)389 1552 y(00000004)370
  567. X1643 y Fl(Figure)14 b(4:)j(A)d(sample)f(RNG)g(state)i(\014le)f(for)f(the)i
  568. X(Kn)o(uth/Ben)o(tley)g(prand\(\).)324 1740 y Ff(RNG)21 b(statefile)f(for)h
  569. X(algorithm)f(4,)h(\(4.3bsd)g(nrand48.c:)e(48-bit)324 1790 y(multiplicative\))
  570. X324 1840 y(Buffer)h(size)h(=)h(8192)f(bytes)324 1889 y(Initial)f(seed)h
  571. X(table)g(=)389 1939 y(0096)65 b(b43f)f(0034)h(bf15)324 2039
  572. Xy(Number)20 b(of)i(calls)e(to)i(underlying)e(RNG)h(after)g(seeding)f(=)h(0)h
  573. X(billion)324 2089 y(+)f(11000)324 2138 y(Next)g(value)g(in)g(this)g
  574. X(pseudorandom)e(sequence)h(=)i(04a3689e)324 2188 y(This)f(RNG)g(returns)f
  575. X(every)h(1)h(generates)324 2238 y(This)f(RNG)g(uses)g(mrandom)f(algorithm)g
  576. X(0)324 2288 y(RNG)h(state)g(table)f(=)389 2338 y(07c5)65 b(8f2d)f(0000)h
  577. X(a7d6)530 2429 y Fl(Figure)14 b(5:)k(A)c(sample)e(RNG)i(state)g(table)g(for)g
  578. XFf(nrand48)p eop
  579. X%%Page: 14 17
  580. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)624
  581. Xb Fl(14)324 294 y Ff(/*)21 b(Proper)g(way)g(to)g(re-initialize)e(an)j(active)
  582. Xe(RNG)h(*/)324 344 y(mrandom\(rng,10,n)o(,v\);)324 394 y(kill_rng\(rng\);)324
  583. X444 y(rng=restart_rng\()o("myst)o(atefi)o(le"\);)324 544 y(/*)g(Proper)g(way)
  584. Xg(to)g(restart)g(an)g(inactive)f(RNG)h(*/)324 593 y(RNGdata)f(*rng;)324
  585. X643 y(rng=restart_rng\()o("myst)o(atefi)o(le"\);)324 743 y(/*)h(Improper)f
  586. X(way)h(to)h(restart)e(an)i(active)e(RNG)h(*/)324 793 y(mrandom\(rng,10,n)o
  587. X(,v\);)324 842 y(rng=restart_rng\()o("myst)o(atefi)o(le"\);)515
  588. X934 y Fl(Figure)14 b(6:)j(Examples)c(of)g(sa)o(ving)h(and)f(restarting)i
  589. X(RNGs)262 1066 y Fh(5.4.4)47 b(Seeding)262 1143 y Fl(Eac)o(h)14
  590. Xb(RNG)g(is)g(initially)e(seeded)k(during)e(initialization)e(b)o(y)i
  591. XFf(init_rng)p Fl(.)j(An)e(RNG)f(ma)o(y)262 1193 y(also)f(b)q(e)h(reseeded)j
  592. X(at)c(an)o(y)h(time)e(after)i(initialization.)324 1292 y Ff(void)21
  593. Xb(seed_rng\(rng,see)o(d\))324 1342 y(RNGdata)f(*rng;)324 1392
  594. Xy(long)h(*seed;)324 1492 y(seed_rng)16 b Fl(seeds)j Ff(rng)e
  595. XFl(with)g(the)i(seed)g(table)e(p)q(oin)o(ted)h(to)f(b)o(y)h
  596. XFf(seed)p Fl(.)28 b(The)18 b(RNG's)262 1541 y(coun)o(ter)c(is)g(reset)i(to)d
  597. X(0)h(and)g(its)g(bu\013ers)h(are)f(\015ushed.)262 1649 y Fh(5.4.5)47
  598. Xb(Chec)o(king)15 b(RNG)h(in)o(tegri)o(t)n(y)262 1726 y Fl(An)f(RNG)g(can)h(b)
  599. Xq(e)g(c)o(hec)o(k)o(ed)h(to)e(see)i(if)e(it)g(has)h(b)q(een)g(corrupted)h(or)
  600. Xf(is)f(otherwise)i(not)e(in)262 1776 y(prop)q(er)f(condition)g(for)f(use.)324
  601. X1875 y Ff(int)21 b(check_rng\(rng\);)324 1925 y(RNGdata)f(*rng;)324
  602. X2025 y(check_rng)12 b Fl(c)o(hec)o(ks)k(the)g(in)o(tegrit)o(y)d(of)h(the)i
  603. X(RNG,)d(in)h(order)h(to)g(determine)f(whether)262 2075 y(it)f(can)h(b)q(e)h
  604. X(used)f(b)o(y)g(the)h(other)f(mrandom)d(library)i(routines.)262
  605. X2183 y Fh(5.4.6)47 b(Obtaining)13 b(a)j(h)o(uman-readabl)o(e)d(description)f
  606. X(of)k(the)e(RNG)324 2259 y Ff(char)21 b(*describe_rng\(rn)o(g,rng)o(id\))324
  607. X2309 y(RNGdata)f(*rng;)324 2359 y(char)h(rngid[RNGIDSTRLE)o(N];)p
  608. Xeop
  609. X%%Page: 15 18
  610. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)624
  611. Xb Fl(15)324 307 y Ff(describe_rng)19 b Fl(places)j(a)g(h)o(uman-readable)e
  612. X(description)j(of)e Ff(rng)g Fl(in)g(the)i(string)262 357 y
  613. XFf(rngid)p Fl(.)16 b(The)f(string)f(has)g(the)g(follo)o(wing)e(format:)324
  614. X457 y Ff(RNG)21 b(state)g(identifier)e(is)j(\(alg,)f(mralg:)f(seed1,)h
  615. X(seed2;)f(count1,count2;)324 506 y(bufsize,)g(split\))324 606
  616. Xy Fl(where)324 697 y Fe(\017)g Ff(alg)11 b Fl(is)f(the)i(n)o(um)o(b)q(er)e
  617. X(of)h(the)g(algorithm)d(used)k(b)o(y)f Ff(rng)f Fl(to)h(generate)h
  618. X(pseudorandom)365 747 y(n)o(um)o(b)q(ers.)18 b(\(See)d(App)q(endix)f(B.\))324
  619. X830 y Fe(\017)20 b Ff(mralg)10 b Fl(is)h(the)g(n)o(um)o(b)q(er)g(of)f(the)h
  620. X(algorithm)e(used)i(b)o(y)g Ff(mrandomrv)e Fl(when)i(called)g(with)365
  621. X880 y Ff(rng)p Fl(.)18 b(\(See)d(Section)f(5.4.2.\))324 963
  622. Xy Fe(\017)20 b Ff(seed1)14 b Fl(and)h Ff(seed2)f Fl(are)i(the)g(\014rst)f
  623. X(and)g(second)i(en)o(tries)f(in)e(t)p Ff(rng)p Fl('s)h(seed)h(table.)22
  624. Xb(If)365 1013 y Ff(rng)p Fl('s)12 b(seed)i(table)e(has)h(more)e(than)h(t)o(w)
  625. Xo(o)g(en)o(tries,)i(only)d(the)i(\014rst)h(t)o(w)o(o)e(are)g(included)365
  626. X1063 y(in)i(its)g(description.)k(\(See)d(Section)f(5.4.4.\))324
  627. X1146 y Fe(\017)20 b Ff(count1)13 b Fl(and)h Ff(count2)e Fl(represen)o(t)k
  628. XFf(rng)p Fl('s)e(coun)o(ter.)19 b(\(See)14 b(Section)h(5.4.1.\))324
  629. X1229 y Fe(\017)20 b Ff(bufsize)13 b Fl(is)g(the)i(n)o(um)o(b)q(er)e(of)g(en)o
  630. X(tries)i(in)f Ff(rng)p Fl('s)f(bu\013er.)19 b(\(See)c(Section)f(5.4.2.\))324
  631. X1312 y Fe(\017)20 b Ff(split)13 b Fl(is)h Ff(rng)p Fl('s)f(curren)o(t)i
  632. X(split)f(v)n(alue.)j(\(See)e(Section)f(5.4.7.\))324 1403 y
  633. XFf(describe_rng)19 b Fl(exits)j(with)f(a)g(message)g(to)h Ff(stderr)e
  634. XFl(if)h(called)g(with)g(an)h(in)o(v)n(alid)262 1453 y Ff(RNGdata)12
  635. Xb Fl(p)q(oin)o(ter.)262 1561 y Fh(5.4.7)47 b(Pro)q(cedures)14
  636. Xb(for)h(examining)f(and)h(mo)q(difying)e(RNG)j(parameters)262
  637. X1637 y Fl(Pro)q(cedures)21 b(are)e(a)o(v)n(ailable)e(for)h(examining)f(and)h
  638. X(mo)q(difying)e(an)j(RNG's)f(parameters)262 1687 y(once)c(it)g(has)g(b)q(een)
  639. Xh(initialized.)324 1787 y Ff(int)21 b(mralg_rng\(rng,)e(new_value\))324
  640. X1837 y(RNGdata)h(*rng;)324 1886 y(long)h(new_value;)324 1986
  641. Xy(int)g(split_rng\(rng,)e(new_value\))324 2036 y(RNGdata)h(*rng;)324
  642. X2086 y(long)h(new_value;)324 2185 y(double)f(range_rng\(rng\))324
  643. X2235 y(RNGdata)g(*rng;)324 2335 y(mralg_rng)e Fl(sets)k Ff(rng)p
  644. XFl('s)e(mrandom)e(algorithm)g(n)o(um)o(b)q(er)h(\(See)j(Section)f(5.4.2)e
  645. X(for)262 2385 y(information)12 b(on)j(mrandom)d(algorithm)g(n)o(um)o(b)q
  646. X(ers\).)22 b(It)16 b(returns)g(0)f(if)g Ff(new_value)e Fl(is)i(an)262
  647. X2434 y(in)o(v)n(alid)c(v)n(alue.)p eop
  648. X%%Page: 16 19
  649. Xbop 262 162 a Fi(5)41 b(USING)14 b(THE)g(MRANDOM)f(P)m(A)o(CKA)o(GE)624
  650. Xb Fl(16)324 294 y Ff(RNGdata)20 b(*rngs[10];)324 344 y(long)h(seed;)324
  651. X394 y(int)g(i;)324 494 y(seed=12345;)324 544 y(for)g(\(i=0;)g(i<10;)f(i++\))h
  652. X({)367 593 y(/*)h(RNG)f(#i)g(gets)g(cycled)g(i)g(times)g(*/)367
  653. X643 y(rng[i]=init_rng\(2,0)o(,&see)o(d,i,0)o(,1024)o(\);)367
  654. X693 y(split\(rng[i],9\);)324 743 y(})615 834 y Fl(Figure)14
  655. Xb(7:)k(Creating)c(\\leapfrogged")e(RNGs)324 967 y Ff(split_rng)20
  656. Xb Fl(sets)k(the)f(split)e(v)n(alue)h(of)g Ff(rng)p Fl(.)42
  657. Xb(It)23 b(returns)h(0)e(if)f Ff(new_value)f(<)i Fl(0.)262 1017
  658. Xy(An)c(RNG's)g(split)g(v)n(alue)g(is)g(set)i(to)e Ff(SPLIT_DEF)e
  659. XFl(up)q(on)j(initialization.)29 b Ff(SPLIT_DEF)17 b Fl(is)262
  660. X1066 y Ff(#define)p Fl(d)12 b(in)h(`)p Ff(mrandom.h)p Fl(',)e(and)j(curren)o
  661. X(tly)g(has)h(a)e(v)n(alue)g(of)h(0.)324 1116 y(The)j(function)g(of)f(the)h
  662. X(split)g(v)n(alue)f(is)g(to)h(sim)o(ulate)e(one)i(\\branc)o(h")g(of)f(a)h
  663. X(generator)262 1166 y(whic)o(h)11 b(has)g(b)q(een)i(\\split")d(in)o(to)g(t)o
  664. X(w)o(o)h(or)g(more)g(generators.)18 b(This)11 b(is)g(b)q(est)i(illustrated)e
  665. X(with)262 1216 y(an)g(example.)17 b(Consider)12 b(an)g(\(apparen)o(tly)g
  666. X(non-random\))f(RNG)g(whic)o(h)h(returns)i(the)f(ra)o(w)262
  667. X1266 y(sequence:)621 1349 y(0)h(1)f(2)h(3)g(4)f(5)h(6)f(7)h(8)g(9)f(10)h(11)f
  668. X(12)g(13)h(14)f(15)g(...)262 1432 y(The)j(split)g(v)n(alue)g(indicates)h(ho)o
  669. X(w)f(man)o(y)e(elemen)o(ts)i(of)g(the)h(sequence)i(to)d(skip)g(b)q(et)o(w)o
  670. X(een)262 1481 y(generates.)j(F)m(or)13 b(example,)f(if)g(our)h(sample)g(RNG)f
  671. X(w)o(ere)i(giv)o(en)f(a)g(split)g(v)n(alue)g(of)g(1)g(imm)o(e-)262
  672. X1531 y(diately)g(after)h(initialization,)d(it)i(w)o(ould)g(then)i(return)g
  673. X(the)f(follo)o(wing)e(sequence:)846 1614 y(0)i(2)f(4)h(6)g(8)f(10)g(...)262
  674. X1697 y(A)g(split)h(v)n(alue)f(of)g(2)h(after)g(initialization)d(w)o(ould)i
  675. X(pro)q(duce:)836 1780 y(0)g(3)h(6)g(9)f(12)g(15)h(...)262 1863
  676. Xy(An)19 b(RNG)g(ma)o(y)f(b)q(e)i(split)f(at)g(an)o(y)g(time)f(after)i(its)g
  677. X(initialization.)32 b(So,)20 b(for)f(example,)262 1913 y(our)14
  678. Xb(sample)g(RNG)f(migh)o(t)g(b)q(e)i(initialized)e(and)i(then)g(made)f(to)g
  679. X(generate)i(the)f(follo)o(wing)262 1963 y(v)n(alues:)881 2046
  680. Xy(0)e(1)h(2)g(3)f(4)h(5)262 2129 y(b)q(efore)g(b)q(eing)g(split)f(with)h(a)g
  681. X(split)f(v)n(alue)g(of)h(3,)f(pro)q(ducing)h(the)g(follo)o(wing)e(generates:)
  682. X832 2212 y(6)i(10)f(14)h(18)f(22)g(...)262 2295 y(Splitting)g(can)h(b)q(e)i
  683. X(used)f(to)f(create)i(sev)o(eral)f(\\leapfrogged")f(RNGs)g(from)f(one)h(RNG,)
  684. Xg(as)262 2345 y(sho)o(wn)f(in)h(Figure)g(7.)324 2395 y(This)c(op)q(eration)g
  685. X(ma)o(y)e(b)q(e)j(useful)f(in)g(parallel)f(co)q(des,)j(as)e(in)g(testing)g
  686. X(an)g(RNG)g(for)g(long-)262 2445 y(range)k(correlations.)21
  687. Xb(Unfortunately)m(,)14 b(our)g(curren)o(t)j(implem)o(en)o(tation)12
  688. Xb(is)i(ine\016cien)o(t)h(for)p eop
  689. X%%Page: 17 20
  690. Xbop 262 162 a Fi(6)41 b(ADDING)13 b(NEW)h(RNGS)f(TO)h(THE)g(P)m(A)o(CKA)o(GE)
  691. X507 b Fl(17)262 307 y(leapfrogging)11 b(large)h(n)o(um)o(b)q(ers)h(of)f
  692. X(RNGs.)17 b(A)c(more)f(e\016cien)o(t)h(metho)q(d)f(ma)o(y)f(b)q(e)i(included)
  693. X262 357 y(in)g(a)h(future)g(v)o(ersion)g(of)f(mrandom.)324
  694. X407 y(The)h(split)g(v)n(alue)g(a\013ects)h(all)e(of)h(the)h(pseudorandom)e(n)
  695. Xo(um)o(b)q(er)h(generating)g(routines)262 457 y(\(See)g(Section)h(5.4.2\).)
  696. X324 506 y Ff(range_rng)d Fl(returns)j(the)g(range)f(of)f Ff(rng)p
  697. XFl(.)262 606 y Fh(NOTES)324 656 y Fl(These)j(pro)q(cedures)h(exit)d(with)g(a)
  698. Xh(message)f(to)g Ff(stderr)g Fl(if)g Ff(rng)f Fl(do)q(es)j(not)e(p)q(oin)o(t)
  699. Xg(to)h(a)262 706 y(v)n(alid)d Ff(RNGdata)g Fl(structure.)262
  700. X843 y Fk(6)69 b(Adding)23 b(new)f(RNGs)g(to)h(the)g(P)n(ac)n(k)l(age)262
  701. X934 y Fl(This)c(section)i(is)f(designed)h(for)e(the)i(programmer)d(who)h
  702. X(wishes)i(to)f(add)g(new)g(RNGs)262 984 y(to)15 b(the)i(mrandom)c(pac)o(k)n
  703. X(age.)24 b(The)16 b(section)h(\014rst)g(describ)q(es)h(the)e(routines)h(whic)
  704. Xo(h)f(m)o(ust)262 1034 y(b)q(e)21 b(pro)o(vided)f(b)o(y)h(the)g(programmer)e
  705. X(to)h(serv)o(e)i(as)f(an)g(in)o(terface)g(b)q(et)o(w)o(een)h(the)f(RNG)262
  706. X1083 y(and)14 b(the)g(mrandom)d(pac)o(k)n(age.)19 b(It)14 b(then)h(describ)q
  707. X(es)h(the)f(RNG)e(parameters)i(whic)o(h)f(m)o(ust)262 1133
  708. Xy(b)q(e)j(de\014ned)h(in)e(a)h(header)g(\014le)g(for)f(the)i(RNG,)d(and)i(ho)
  709. Xo(w)f(these)i(parameters)f(are)g(to)g(b)q(e)262 1183 y(incorp)q(orated)j(in)o
  710. X(to)f(the)i(co)q(de)f(for)g(mrandom)d(itself.)35 b(Finally)m(,)19
  711. Xb(it)g(describ)q(es)j(ho)o(w)e(to)262 1233 y(remak)o(e)c(the)h(mrandom)d(pac)
  712. Xo(k)n(age)j(after)g(adding)f(or)h(mo)q(difying)c(RNGs.)27 b(App)q(endix)17
  713. Xb(B)262 1283 y(con)o(tains)g(descriptions)i(of)f(the)g(ten)h(RNGs)f
  714. X(installed)f(in)g(the)i(curren)o(t)g(v)o(ersion)g(of)e(the)262
  715. X1332 y(pac)o(k)n(age.)262 1449 y Fd(6.1)55 b(Routines)18 b(Pro)n(vided)g(b)n
  716. X(y)h(the)f(Programmer)262 1525 y Fh(6.1.1)47 b(In)o(tro)q(duction)262
  717. X1602 y Fl(This)17 b(section)i(describ)q(es)h(routines)e(whic)o(h)g(m)o(ust)f
  718. X(b)q(e)i(pro)o(vided)e(b)o(y)h(eac)o(h)g(RNG)g(in)f(the)262
  719. X1652 y(pac)o(k)n(age.)324 1701 y(The)k(routines)g(pro)o(vided)f(b)o(y)h(the)g
  720. X(programmer)d(m)o(ust)h(manipulate)g(an)h Ff(RNGdata)262 1751
  721. Xy Fl(structure.)j(In)16 b(order)f(to)g(facilitate)f(this,)h(t)o(w)o(o)g
  722. X(macros)f(are)i(a)o(v)n(ailable)d(for)i(accessing)h(an)262
  723. X1801 y(RNG's)d(state)h(and)g(seed)h(v)o(ectors:)324 1884 y
  724. XFe(\017)20 b Ff(RNGstate)12 b Fl(refers)k(to)e(the)g(RNG's)f(state)i(v)o
  725. X(ector.)324 1967 y Fe(\017)20 b Ff(RNGseed)13 b Fl(refers)i(to)f(the)g(RNG's)
  726. Xf(seed)i(v)o(ector.)262 2050 y(These)j(v)o(ectors)g(are)f(one-dimensional)e
  727. X(C)h(arra)o(ys,)i(e.g.)26 b Ff(RNGstate[0])15 b Fl(is)i(the)g(\014rst)h(el-)
  728. X262 2100 y(emen)o(t)d(in)g(the)i(RNG's)e(state)h(v)o(ector,)h
  729. XFf(RNGstate[1])c Fl(is)j(the)g(second)h(elemen)o(t,)f(etc.)25
  730. Xb(In)262 2150 y(order)17 b(to)g(mak)o(e)f(use)i(of)f(these)h(macros,)f(the)h
  731. X(name)e(of)g(the)i Ff(RNGdata)e Fl(p)q(oin)o(ter)h(in)g(y)o(our)262
  732. X2200 y(routines')c(parameter)f(lists)h Fc(must)g Fl(b)q(e)g
  733. XFf(rng)p Fl(,)f(as)h(sho)o(wn)g(in)g(the)g(examples)f(in)g(this)h(section.)
  734. X324 2249 y(The)j(names)g(used)h(as)f(examples)f(in)h(this)g(section)h(b)q
  735. X(egin)f(with)g(\\)p Ff(myrng)p Fl(";)f(ho)o(w)o(ev)o(er,)262
  736. X2299 y(there)g(are)f(no)g(restrictions)h(on)f(naming)e(of)h(routines)i(pro)o
  737. X(vided)e(b)o(y)h(an)g(RNG.)f(Ho)o(w)o(ev)o(er,)262 2349 y(for)f(ease)j(of)d
  738. X(readabilit)o(y)g(and)h(consistency)m(,)h(w)o(e)g(suggest)g(that)f(the)h
  739. X(naming)d(con)o(v)o(en)o(tions)262 2399 y(used)j(in)g(this)g(section)g(b)q(e)
  740. Xh(follo)o(w)o(ed.)p eop
  741. X%%Page: 18 21
  742. Xbop 262 162 a Fi(6)41 b(ADDING)13 b(NEW)h(RNGS)f(TO)h(THE)g(P)m(A)o(CKA)o(GE)
  743. X507 b Fl(18)324 307 y(The)10 b(routines)h(describ)q(ed)h(in)d(this)i(section)
  744. Xf(should)g(b)q(e)h(included)f(in)g(a)f(single)h Ff(.c)g Fl(\014le.)17
  745. Xb(A)262 357 y(template)11 b(for)h(suc)o(h)h(a)f(source)h(\014le,)f(called)g
  746. X(`)p Ff(newrng.c)p Fl(',)e(is)i(included)g(in)g(the)h(distribution)262
  747. X407 y(and)g(displa)o(y)o(ed)h(in)f(Figure)h(8.)324 457 y(Remem)o(b)q(er)8
  748. Xb(that)j(all)e(RNG)g(state)i(information)c(m)o(ust)j(b)q(e)g(included)h(in)e
  749. X(the)i Ff(RNGstate)262 506 y Fl(\014eld)f(of)g(the)i Ff(RNGdata)d
  750. XFl(structure.)19 b(In)11 b(particular,)f(do)h Fc(not)g Fl(use)h(global)d(or)h
  751. X(static)h(v)n(ariables)262 556 y(to)h(hold)g(RNG)g(state)i(information.)g
  752. X(Doing)e(so)h(will)e(mak)o(e)g(it)h(imp)q(ossible)f(to)i(run)g(sev)o(eral)262
  753. X606 y(instan)o(tiations)f(of)i(y)o(our)f(RNG)g(sim)o(ulataneously)m(.)262
  754. X714 y Fh(6.1.2)47 b(Seeding)14 b(Routine)324 791 y Ff(void)21
  755. Xb(myrng_seed\(rng,)d(seed\))324 840 y(RNGdata)i(*rng;)324 890
  756. Xy(long)h(*seed;)324 990 y Fl(This)13 b(pro)q(cedure)i(is)e(used)h(for)e
  757. X(seeding)i(the)g(RNG.)d(The)j(in)o(terpretation)f(of)g(the)g
  758. XFf(seed)262 1040 y Fl(parameter)18 b(is)g(left)h(en)o(tirely)g(to)f(the)h
  759. X(programmer.)30 b(It)19 b(ma)o(y)m(,)e(for)h(example,)h(p)q(oin)o(t)f(to)262
  760. X1089 y(a)f(single)g(in)o(teger)h(or)f(to)g(an)g(arra)o(y)h(of)e(5,000)g(in)o
  761. X(tegers.)30 b(One)18 b(of)f(the)h(RNGs)f(curren)o(tly)262 1139
  762. Xy(installed)c(in)h(the)h(pac)o(k)n(age)f(in)o(terprets)i(the)f
  763. XFf(seed)e Fl(parameter)h(as)g(p)q(oin)o(ting)g(to)g(three)h(16-)262
  764. X1189 y(bit)10 b(in)o(tegers.)18 b(Ob)o(viously)m(,)10 b(RNGs)h(whic)o(h)g
  765. X(are)h(capable)f(of)g(b)q(eing)g(seeded)i(with)e(a)g(v)n(ariable)262
  766. X1239 y(n)o(um)o(b)q(er)19 b(of)h(seeds)i(need)g(to)e(b)q(e)h(passed)h(a)e
  767. X(seed)i(p)q(oin)o(ter)e(whic)o(h)h(con)o(tains)f(adequate)262
  768. X1289 y(information)10 b(ab)q(out)k(the)h(n)o(um)o(b)q(er)e(of)g(seeds)j(to)d
  769. X(whic)o(h)h(it)g(p)q(oin)o(ts.)324 1339 y(Although)g(the)i(seeding)g(pro)q
  770. X(cedure)h(is)d(passed)j(an)d(en)o(tire)i Ff(RNGdata)e Fl(structure)j(as)e(a)
  771. X262 1388 y(parameter,)c(it)h(should)g(only)g(manipulate)e(the)j
  772. XFf(RNGstate)e Fl(\014eld)h(of)g(that)g(structure.)20 b(\(See)262
  773. X1438 y(App)q(endix)e(A)f(for)h(information)d(on)i(the)i Ff(RNGdata)d
  774. XFl(structure.\))32 b(Man)o(y)17 b(RNG)g(seeding)262 1488 y(pro)q(cedures)k
  775. X(will)d(simply)f(cop)o(y)i(the)h(seed)g(parameter)f(in)o(to)f
  776. XFf(RNGstate)p Fl(,)h(as)g(sho)o(wn)g(in)262 1538 y(Figure)14
  777. Xb(9.)324 1588 y(Other)j(seeding)f(pro)q(cedures)i(ma)o(y)c(\014ll)h
  778. XFf(RNGstate)f Fl(with)h(the)h(results)h(of)e(some)g(com-)262
  779. X1637 y(plicated)e(function)h(p)q(erformed)f(on)h(the)h(initial)d(seed)j
  780. X(table.)262 1745 y Fh(6.1.3)47 b(Pseudorandom)13 b(Num)o(b)q(er)i(Generating)
  781. Xe(Pro)q(cedure)324 1822 y Ff(long)21 b(myrng_lgen\(rng\))324
  782. X1872 y(RNGdata)f(*rng;)324 1971 y(double)g(myrng_dgen\(rng\))324
  783. X2021 y(RNGdata)g(*rng;)324 2121 y Fl(The)13 b(programmer)e(m)o(ust)g(pro)o
  784. X(vide)i Fc(one)g Fl(pro)q(cedure,)i(matc)o(hing)c(one)i(of)f(the)h(t)o(w)o(o)
  785. Xg(pro-)262 2171 y(tot)o(yp)q(es)e(giv)o(en)g(ab)q(o)o(v)o(e,)g(whic)o(h)f
  786. X(returns)j(a)e(single)f(generate)i(from)e(the)h(RNG.)f(The)h(routine)262
  787. X2220 y(ma)o(y)g(return)16 b(either:)324 2303 y Fe(\017)k Fl(a)14
  788. Xb(double)g(precision)g(\015oating)f(p)q(oin)o(t)g(n)o(um)o(b)q(er)g(in)h(the)
  789. Xg(range)g([0,1\),)f(or)324 2386 y Fe(\017)20 b Fl(a)14 b(long)f(\(32-bit\))g
  790. X(in)o(teger)h(in)g(the)g(range)g(0..)p Ff(range_rng\(rng\))o
  791. XFl(-1)p eop
  792. X%%Page: 19 22
  793. Xbop 262 162 a Fi(6)41 b(ADDING)13 b(NEW)h(RNGS)f(TO)h(THE)g(P)m(A)o(CKA)o(GE)
  794. X507 b Fl(19)324 401 y Ff(/*)21 b(newrng.c)f(*/)324 450 y(/*)h(RNG)g(source)g
  795. X(file)g(template)f(*/)324 500 y(/*)h(Robert)g(Plotkin)324 550
  796. Xy(/*)g(5/3/93)g(*/)324 650 y(#include)f("newrng.h")324 749
  797. Xy(/*)h(Generating)f(procedure)g(*/)324 799 y(/*)h(Only)g(one)g(of)h(the)f
  798. X(following)f(two)h(procedures)f(should)g(be)i(*/)324 849 y(/*)f(defined,)f
  799. X(depending)g(on)i(the)f(kind)g(of)g(value)g(that)g(*/)324 899
  800. Xy(/*)g(your)g(RNG)g(returns)g(*/)324 998 y(long)g(newrng_lgen\(rng\))324
  801. X1048 y(RNGdata)f(*rng;)324 1098 y({)324 1148 y(/*)h(Your)g(generating)f
  802. X(procedure)g(goes)h(here)g(*/)324 1198 y(})324 1297 y(double)f
  803. X(newrng_dgen\(rng\))324 1347 y(RNGdata)g(*rng;)324 1397 y({)324
  804. X1447 y(/*)h(Your)g(generating)f(procedure)g(goes)h(here)g(*/)324
  805. X1496 y(})324 1596 y(/*)g(Seeding)g(procedure)e(*/)324 1646
  806. Xy(void)i(newrng_seed\(rng,)o(seed\))324 1696 y(RNGdata)f(*rng;)324
  807. X1746 y(long)h(*seed;)324 1795 y({)324 1845 y(/*)g(Your)g(seeding)f(procedure)
  808. Xg(goes)h(here)g(*/)324 1895 y(})324 1995 y(/*)g(Checking)f(procedure)g(*/)324
  809. X2044 y(int)h(newrng_check\(rng\))324 2094 y(RNGdata)f(*rng;)324
  810. X2144 y({)324 2194 y(/*)h(Your)g(checking)f(procedure)g(goes)h(here)g(*/)324
  811. X2244 y(})656 2335 y Fl(Figure)14 b(8:)k(RNG)13 b(source)i(\014le)f(template)p
  812. Xeop
  813. X%%Page: 20 23
  814. Xbop 262 162 a Fi(6)41 b(ADDING)13 b(NEW)h(RNGS)f(TO)h(THE)g(P)m(A)o(CKA)o(GE)
  815. X507 b Fl(20)324 294 y Ff(void)21 b(myrng_seed\(rng,)d(seed\))324
  816. X344 y(RNGdata)i(*rng;)324 394 y(long)h(*seed;)324 444 y({)324
  817. X494 y(RNGstate[0]=seed)o([0];)324 544 y(RNGstate[1]=seed)o([1];)d(/*)k(This)f
  818. X(RNG)g(uses)g(two)g(long)g(seeds)g(*/)324 593 y(})633 685 y
  819. XFl(Figure)14 b(9:)j(A)d(sample)f(seeding)i(pro)q(cedure)324
  820. X771 y Ff(long)21 b(myrng_lgen\(rng\))324 821 y(RNGdata)f(*rng;)324
  821. X871 y({)324 921 y(RNGstate[0]*=123)o(45+67)o(89;)324 971 y(return\(RNGstate[)
  822. Xo(0]\);)324 1020 y(})594 1112 y Fl(Figure)14 b(10:)j(A)d(sample)f(generating)
  823. Xh(pro)q(cedure)262 1244 y(It)h(is)f(p)q(oin)o(tless)i(for)e(the)i(programmer)
  824. Xc(to)j(pro)o(vide)g(pro)q(cedures)i(of)e(b)q(oth)g(t)o(yp)q(es.)22
  825. Xb(If)15 b(this)262 1294 y(is)e(done,)g(only)f(one)i(of)e(them)h(will)f(b)q(e)
  826. Xi(accessible)g(b)o(y)f(an)o(y)g(user)h(co)q(de,)g(dep)q(ending)g(on)f(the)262
  827. X1344 y(v)n(alue)g(giv)o(en)g(to)h Ff(RNGreturns)p Fl(,)d Ff(RNGdgen)p
  828. XFl(,)h(and)i Ff(RNGlgen)e Fl(\(see)j(Section)g(6.2\).)324 1394
  829. Xy(Although)d(the)h(generating)g(pro)q(cedure)h(is)f(passed)h(an)e(en)o(tire)h
  830. XFf(RNGdata)e Fl(structure,)k(it)262 1444 y(should)9 b(only)g(manipulate)f
  831. X(the)i Ff(RNGstate)e Fl(\014eld)i(of)f(the)h(structure.)19
  832. Xb(A)10 b(sample)e(generating)262 1493 y(pro)q(cedure)15 b(is)f(displa)o(y)o
  833. X(ed)f(in)h(Figure)g(10.)262 1601 y Fh(6.1.4)47 b(RNG)16 b(Chec)o(king)f(Pro)q
  834. X(cedure)324 1678 y Ff(int)21 b(myrng_check\(rng\))324 1728
  835. Xy(RNGdata)f(*rng;)324 1827 y Fl(The)g(programmer)d(m)o(ust)i(pro)o(vide)h(a)f
  836. X(pro)q(cedure)j(to)e(c)o(hec)o(k)g(the)h(in)o(tegrit)o(y)e(of)g(the)262
  837. X1877 y Ff(RNGdata)d Fl(structure.)32 b(The)18 b(pro)q(cedure)i(returns)g(a)d
  838. X(v)n(alue)h(of)f(1)g(if)h(the)g(RNG)f(is)h(\014t)g(for)262
  839. X1927 y(use,)h(and)f(returns)i(0)d(otherwise.)32 b(The)18 b(co)q(ding)g(of)g
  840. X(the)g(pro)q(cedure)i(is)e(en)o(tirely)h(RNG-)262 1977 y(sp)q(eci\014c,)14
  841. Xb(and)g(ma)o(y)e(b)q(e)j(extremely)e(simple)g(or)h(extremely)f(complicated,)f
  842. X(dep)q(ending)j(on)262 2027 y(the)g(nature)h(of)f(the)g(RNG)g(and)g(the)g
  843. X(exten)o(t)i(of)d(in)o(tegrit)o(y)h(desired.)23 b(On)15 b(one)g(extreme)h(is)
  844. X262 2077 y(the)g(pro)q(cedure)j(whic)o(h)d(alw)o(a)o(ys)f(declares)j
  845. X(success,)h(and)d(on)g(the)h(other)g(extreme)g(is)f(the)262
  846. X2126 y(p)q(erfect)e(\(and)g(slo)o(w\))f(pro)q(cedure)i(whic)o(h)e(creates)i
  847. X(a)e(new)h(RNG,)e(seeds)j(it)e(with)g(the)h(seeds)262 2176
  848. Xy(of)c(the)i(RNG)e(to)i(b)q(e)f(c)o(hec)o(k)o(ed,)i(cycles)f(it)f(through)h
  849. X(the)f(n)o(um)o(b)q(er)g(of)g(generates)i(whic)o(h)e(w)o(ere)262
  850. X2226 y(pro)q(duced)k(b)o(y)f(the)g(RNG)g(to)g(b)q(e)g(c)o(hec)o(k)o(ed,)h
  851. X(and)f(compares)g(the)h(state)g(tables)f(of)f(the)i(t)o(w)o(o)262
  852. X2276 y(RNGs.)21 b(Clearly)m(,)14 b(the)h(pro)q(cedure)i(should)e(not)g(mo)q
  853. X(dify)e(the)i(RNG)g(in)f(an)o(y)h(w)o(a)o(y)m(.)20 b(When)262
  854. X2326 y(writing)c(a)g(c)o(hec)o(king)h(pro)q(cedure)i(it)e(migh)o(t)e(b)q(e)i
  855. X(useful)g(to)g(examine)e(those)j(included)f(in)262 2375 y(the)d(existing)g
  856. X(pac)o(k)n(age.)p eop
  857. X%%Page: 21 24
  858. Xbop 262 162 a Fi(6)41 b(ADDING)13 b(NEW)h(RNGS)f(TO)h(THE)g(P)m(A)o(CKA)o(GE)
  859. X507 b Fl(21)324 294 y Ff(/*)21 b(newrng.h)f(*/)324 344 y(/*)h(RNG)g(header)g
  860. X(file)g(template)f(*/)324 394 y(/*)h(Robert)g(Plotkin)324 444
  861. Xy(/*)g(5/3/93)g(*/)324 544 y(#include)f("mrandom.h")324 643
  862. Xy(/*)h(Information)f(for)h(mrandom)f(*/)324 693 y(#define)g(RNGstatesize_n)
  863. X324 743 y(#define)g(RNGseedsize_2)324 793 y(#define)g(RNGrange_2)324
  864. X842 y(#define)g(RNGname_2)324 892 y(#define)g(RNGreturns_2)324
  865. X942 y(#define)g(RNGstatetype_2)324 992 y(#define)g(RNGdgen_2)324
  866. X1042 y(#define)g(RNGlgen_2)324 1092 y(#define)g(RNGseed_2)324
  867. X1141 y(#define)g(RNGcheck_2)324 1241 y(/*)h(mrandom)g(interface)e(routines)i
  868. X(*/)324 1291 y(long)g(newrng_gen\(/*)e(RNGdata)h(*)i(*/\);)324
  869. X1341 y(void)f(newrng_seed\(/*)e(RNGdata)h(*,)h(long)g(*)h(*/\);)324
  870. X1390 y(int)f(newrng_check\(/*)e(RNGdata)h(*)i(*/\);)642 1482
  871. Xy Fl(Figure)14 b(11:)k(RNG)13 b(header)i(\014le)f(template)262
  872. X1614 y Fd(6.2)55 b(RNG)19 b(Header)e(Files)262 1691 y Fl(F)m(or)d(eac)o(h)i
  873. X(RNG)f(included)g(in)g(the)h(pac)o(k)n(age,)f(there)h(m)o(ust)f(b)q(e)g(a)g
  874. X(corresp)q(onding)i(header)262 1741 y(\014le.)i(The)c(header)g(\014le)f(con)o
  875. X(tains)g(information)e(ab)q(out)i(the)h(RNG)e(whic)o(h)i(is)f(used)h(b)o(y)f
  876. X(the)262 1791 y(mrandom)d(library)i(routines.)20 b(This)15
  877. Xb(section)g(describ)q(es)h(the)f(information)d(con)o(tained)i(in)262
  878. X1840 y(RNG)d(header)i(\014les,)f(and)g(describ)q(es)i(ho)o(w)d(to)h(use)h
  879. X(suc)o(h)g(header)f(\014les)h(to)f(incorp)q(orate)g(new)262
  880. X1890 y(RNGs)18 b(in)o(to)g(the)h(mrandom)d(pac)o(k)n(age.)32
  881. Xb(A)19 b(template)f(for)g(suc)o(h)h(a)g(header)g(\014le,)h(called)262
  882. X1940 y(`)p Ff(newrng.h)p Fl(',)10 b(is)k(included)g(in)g(the)g(distribution)f
  883. X(and)h(displa)o(y)o(ed)f(in)h(Figure)g(11.)262 2048 y Fh(6.2.1)47
  884. Xb(Information)13 b(in)i(Header)g(Files)262 2125 y Fl(Eac)o(h)f(header)h
  885. X(\014le)e(should)h(b)q(egin)g(with)g(the)g(follo)o(wing)d(directiv)o(es:)324
  886. X2224 y Ff(#ifndef)20 b(MRANDOM)324 2274 y(#include)g("mrandom.h")324
  887. X2324 y(#endif)p eop
  888. X%%Page: 22 25
  889. Xbop 262 162 a Fi(6)41 b(ADDING)13 b(NEW)h(RNGS)f(TO)h(THE)g(P)m(A)o(CKA)o(GE)
  890. X507 b Fl(22)262 307 y Fh(De\014niti)o(on)12 b(of)k(RNG)f(parameters)324
  891. X407 y Fl(The)i(next)h(set)g(of)f(lines)g(in)f(the)i(\014le)f(should)g(con)o
  892. X(tain)g Ff(#define)e Fl(statemen)o(ts)j(whic)o(h)262 457 y(assign)13
  893. Xb(v)n(alues)h(to)g(the)g(RNG's)g(parameters.)k(The)c(names)f(used)i(in)f(the)
  894. Xg Ff(#define)f Fl(state-)262 506 y(men)o(ts)d(m)o(ust)g(con)o(tain)h(the)h
  895. X(RNG's)e(n)o(um)o(b)q(er.)16 b(There)c(are)g(curren)o(tly)g(ten)g(RNGs)e
  896. X(included)262 556 y(in)16 b(the)i(pac)o(k)n(age,)f(lab)q(eled)g(0)g(through)g
  897. X(9.)27 b(The)18 b(next)f(RNG)f(included)i(in)e(the)i(pac)o(k)n(age)262
  898. X606 y(should)d(b)q(e)h(lab)q(eled)g(n)o(um)o(b)q(er)f(10,)g(and)h(so)g(on.)23
  899. Xb(The)16 b(\\)p Ff(n)p Fl(")f(in)h(eac)o(h)g(parameter)f(name)g(in)262
  900. X656 y(the)f(follo)o(wing)d(list)j(should)f(b)q(e)i(in)o(terpreted)g(as)f(the)
  901. Xh(RNG's)e(n)o(um)o(b)q(er.)262 729 y Ff(RNGname_n)18 b Fl(A)11
  902. Xb(string)g(constan)o(t)h(con)o(taining)d(the)j(name)d(of)i(the)g(RNG,)f
  903. X(terminated)g(with)365 779 y(a)k(newline)g(c)o(haracter.)262
  904. X855 y Ff(RNGstatesize_n)j Fl(The)f(n)o(um)o(b)q(er)e(of)h(en)o(tries)h(in)e
  905. X(the)i(RNG's)e(state)i(table.)22 b(Eac)o(h)15 b(en)o(try)365
  906. X905 y(is)g(a)f(\(32-bit\))g Ff(long)p Fl(.)19 b(If)14 b(the)h(RNG)f(is)h
  907. X(capable)f(of)g(using)h(state)g(tables)g(of)f(v)n(arying)365
  908. X955 y(sizes,)h Ff(RNGstatesize_n)c Fl(should)i(b)q(e)i(de\014ned)g(as)f(the)g
  909. X(maxim)o(um)9 b(p)q(ossible)14 b(size.)262 1030 y Ff(RNGseedsize_n)k
  910. XFl(The)11 b(n)o(um)o(b)q(er)g(of)g(en)o(tries)h(in)f(the)h(RNG's)e(seed)j
  911. X(table.)k(Eac)o(h)12 b(en)o(try)g(is)f(a)365 1080 y(\(32-bit\))i
  912. XFf(long)p Fl(.)k(If)c(the)h(RNG)e(is)h(capable)g(of)g(using)g(seed)i(tables)e
  913. X(of)g(v)n(arying)f(sizes,)365 1130 y Ff(RNGseedsize_n)f Fl(should)j(b)q(e)h
  914. X(de\014ned)g(as)f(the)g(maxim)n(um)c(p)q(ossible)k(size.)262
  915. X1206 y Ff(RNGrange_n)k Fl(The)h(range)f(of)f(the)i(RNG,)e(expressed)j(as)e(a)
  916. Xg(double)g(precision)h(\015oating)365 1256 y(p)q(oin)o(t)f(n)o(um)o(b)q(er.)
  917. X29 b(The)19 b(range)f(of)f(the)i(RNG)e(is)h(one)g(more)f(than)h(the)h(maxim)n
  918. X(um)365 1305 y(v)n(alue)12 b(the)i(RNG)e(is)g(capable)h(of)f(generating.)18
  919. Xb(F)m(or)12 b(RNGs)g(whic)o(h)h(pro)q(duce)h(double)365 1355
  920. Xy(precision)f(generates)h(with)e(a)h(precision)f(of)g(p)h(\(i.e.)k(in)12
  921. Xb(the)h(range)g([0)p Fg(;)7 b Fl(\()p Ff(RNGrange)s Fe(\000)365
  922. X1405 y Fl(1)p Fg(:)p Fl(0\))p Fg(=)p Fl(\(1)k Fg(<<)h(p)p Fl(\)\),)h
  923. XFf(RNGrange)e Fl(should)i(b)q(e)h(de\014ned)h(as)e(2)1246 1390
  924. Xy Fa(p)1265 1405 y Fl(.)18 b(F)m(or)13 b(example,)e(an)i(RNG)365
  925. X1455 y(whic)o(h)d(pro)q(duces)h(8-b)o(yte)f(IEEE)g(\015oating-p)q(oin)o(t)e
  926. X(generates)j(using)f(single-precision)365 1505 y(IEEE)15 b(arithmetic)e
  927. X(\(24-bit)g(man)o(tissas\))f(has)j(a)e(range)h(of)f(16777216.0.)262
  928. X1581 y Ff(RNGreturns_n)18 b Fl(A)f(n)o(um)o(b)q(er)g(signifying)e(the)j(t)o
  929. X(yp)q(e)f(of)g(the)h(generate)g(returned)h(b)o(y)e(the)365
  930. X1630 y(RNG.)c(An)h(RNG)f(can)h(return)h(a)f(v)n(alue)f(of)g(one)h(of)g(t)o(w)
  931. Xo(o)f(t)o(yp)q(es:)415 1706 y Fe(\017)21 b Fl(a)13 b Ff(long)g
  932. XFl(in)h(the)g(range)g(0..)p Ff(RNGrange)p Fl(-1)415 1765 y
  933. XFe(\017)21 b Fl(a)13 b Ff(double)g Fl(in)g(the)i(range)f([0,1\))365
  934. X1841 y(RNGs)c(whic)o(h)g(return)h(v)n(alues)e(of)h(t)o(yp)q(e)g
  935. XFf(long)f Fl(and)h Ff(double)e Fl(return)k(t)o(yp)q(es)e Ff(RET_LONG)365
  936. X1891 y Fl(and)k Ff(RET_DOUBLE)p Fl(,)d(resp)q(ectiv)o(ely)m(,)k(as)f
  937. X(de\014ned)h(in)e(`)p Ff(mrandom.h)p Fl('.)262 1967 y Ff(RNGstatetype)18
  938. Xb Fl(A)f(n)o(um)o(b)q(er)f(signifying)g(the)h(in)o(terpretation)h(of)e(the)i
  939. X(v)n(alues)f(stored)h(in)365 2017 y(the)c(RNG's)e(state)i(and)e(seed)i(v)o
  940. X(ectors.)19 b(This)13 b(v)n(alue)f(is)h(used)h(b)o(y)f(the)g(routines)h(that)
  941. X365 2067 y(read)g(and)g(write)g(the)g(ASCI)q(I)g(state)h(\014les,)e(thereb)o
  942. X(y)i(allo)o(wing)c(p)q(ortabilit)o(y)i(of)g(state)365 2116
  943. Xy(\014les)f(across)h(mac)o(hines)e(with)h(di\013eren)o(t)g(b)o(yte)h
  944. X(orderings)f(\(see)h(Section)f(5.4.3\).)k(The)365 2166 y(follo)o(wing)c(v)n
  945. X(alues)h(are)h(curren)o(tly)h(supp)q(orted:)732 2250 y(V)m(alue)160
  946. Xb(T)o(yp)q(e)p 707 2267 645 2 v 732 2351 a Ff(STATE)p 845 2351
  947. X14 2 v 15 w(CHAR)49 b Fl(8-bit)13 b(c)o(haracter)732 2401 y
  948. XFf(STATE)p 845 2401 V 15 w(INT)71 b Fl(16-bit)13 b(in)o(teger)732
  949. X2451 y Ff(STATE)p 845 2451 V 15 w(LONG)49 b Fl(32-bit)13 b(long)f(in)o(teger)
  950. Xp eop
  951. X%%Page: 23 26
  952. Xbop 262 162 a Fi(6)41 b(ADDING)13 b(NEW)h(RNGS)f(TO)h(THE)g(P)m(A)o(CKA)o(GE)
  953. X507 b Fl(23)365 307 y(The)10 b(v)n(alues)f(of)g Ff(STATE)p
  954. X721 307 14 2 v 14 w(FLOAT)g Fl(\(IEEE-standard)h(32-bit)e(\015oat\))h(and)g
  955. XFf(STATE)p 1559 307 V 15 w(DOUBLE)365 357 y Fl(\(IEEE-standard)k(64-bit)e
  956. X(\015oat\))g(are)i(not)e(curren)o(tly)i(supp)q(orted)g(and)e(are)i(reserv)o
  957. X(ed)365 407 y(for)h(future)g(use.)262 490 y Ff(RNGdgen_n)g
  958. XFh(and)h Ff(RNGlgen_n)k Fl(The)14 b(lab)q(el)f(of)h(the)g(pro)q(cedure)i(to)e
  959. X(b)q(e)g(used)h(for)f(generat-)365 540 y(ing)f(pseudorandom)f(n)o(um)o(b)q
  960. X(ers.)17 b(If)c(the)g(RNG)f(returns)j Ff(double)p Fl(s,)d(then)h
  961. XFf(RNG_dgen)365 589 y Fl(should)20 b(b)q(e)i(de\014ned)f(as)f(the)h(lab)q(el)
  962. Xf(of)g(the)h(RNG)f(generating)g(pro)q(cedure,)k(and)365 639
  963. Xy Ff(RNG_lgen)8 b Fl(should)h(b)q(e)h(de\014ned)g(as)g(0.)16
  964. Xb(If)9 b(the)h(RNG)e(returns)j Ff(long)p Fl(s,)e(then)h Ff(RNG_lgen)365
  965. X689 y Fl(should)20 b(b)q(e)i(de\014ned)f(as)f(the)h(lab)q(el)f(of)g(the)h
  966. X(RNG)f(generating)g(pro)q(cedure,)k(and)365 739 y Ff(RNG_dgen)12
  967. Xb Fl(should)i(b)q(e)h(de\014ned)g(as)f(0.)262 822 y Ff(RNGseed_n)k
  968. XFl(The)d(lab)q(el)e(of)g(the)i(pro)q(cedure)h(to)d(b)q(e)i(used)g(for)e
  969. X(seeding)i(the)f(RNG.)262 905 y Ff(RNGcheck_n)k Fl(The)c(lab)q(el)e(of)h(the)
  970. Xh(pro)q(cedure)h(to)e(b)q(e)h(used)g(for)e(c)o(hec)o(king)i(the)g(in)o
  971. X(tegrit)o(y)e(of)365 955 y(the)j(RNG.)262 1046 y Fh(Pro)q(cedure)f(protot)o
  972. X(yp)q(es)324 1146 y Fl(Finally)m(,)f(the)j(header)g(\014le)f(m)o(ust)f(con)o
  973. X(tain)h(function)g(protot)o(yp)q(es)h(for)e(the)i(three)h(pro-)262
  974. X1196 y(cedures)h(pro)o(vided)e(b)o(y)g(the)h(RNG,)e(so)h(that)h(the)f(pro)q
  975. X(cedures)j(can)d(b)q(e)h(accessed)i(b)o(y)d(the)262 1245 y(main)11
  976. Xb(mrandom)g(co)q(de.)19 b(F)m(or)14 b(example:)324 1345 y Ff(long)21
  977. Xb(myrng_gen\(\);)324 1395 y(void)g(myrng_seed\(\);)324 1445
  978. Xy(int)g(myrng_check\(\);)262 1561 y Fd(6.3)55 b(Mo)r(difying)18
  979. Xb(the)g(mrandom)e(co)r(de)262 1637 y Fl(Only)i(a)h(few)g(lines)g(of)g(`)p
  980. XFf(mrandom.h)p Fl(')d(and)j(`)p Ff(mrandom.c)p Fl(')e(need)j(to)f(b)q(e)g(mo)
  981. Xq(di\014ed)f(when)262 1687 y(adding)13 b(a)g(new)i(RNG)e(to)g(the)i(pac)o(k)n
  982. X(age.)324 1779 y Fe(\017)20 b Fl(The)i(n)o(um)o(b)q(er)e(of)h(RNGs)g(curren)o
  983. X(tly)h(installed)e(in)h(the)h(pac)o(k)n(age)e(is)h(de\014ned)i(as)365
  984. X1828 y Ff(NUM_RNGS)18 b Fl(in)g(`)p Ff(mrandom.h)p Fl('.)31
  985. Xb(The)20 b(curren)o(t)g(v)n(alue)e(is)h(10.)33 b(This)19 b(v)n(alue)g(should)
  986. X365 1878 y(b)q(e)c(incremen)o(ted)f(when)g(a)g(new)g(RNG)f(is)h(added)g(to)g
  987. X(the)h(pac)o(k)n(age.)324 1961 y Fe(\017)20 b Fl(The)15 b(header)g(\014le)f
  988. X(for)g(the)h(new)f(RNG)g(needs)h(to)f(b)q(e)h Ff(#include)p
  989. XFl(d)d(in)i(`)p Ff(mrandom.c)p Fl('.)365 2011 y(The)i Ff(#include)d
  990. XFl(directiv)o(e)i(should)g(b)q(e)g(included)g(in)g(the)g(section)h(mark)o(ed)
  991. Xd(b)o(y)i(the)365 2061 y(commen)o(t)7 b(\\)p Ff(Header)21 b(files)f(for)i
  992. X(RNGs)f(currently)f(included)g(in)h(package.)p Fl(")324 2144
  993. Xy Fe(\017)f Fl(Sev)o(eral)11 b(additions)f(need)h(to)f(b)q(e)h(made)f(in)g(`)
  994. Xp Ff(mrandom.c)p Fl(')d(in)j(the)h(section)h(mark)o(ed)d(b)o(y)365
  995. X2194 y(the)23 b(commen)o(t)d(\\)p Ff(Arrays)g(to)i(hold)f(information)e
  996. X(about)i(RNGs.)p Fl(")g(This)h(sec-)365 2243 y(tion)17 b(of)f(the)i(co)q(de)g
  997. X(declares)g(and)f(initializes)f(sev)o(eral)i(arra)o(ys)f(whic)o(h)g(hold)g
  998. X(infor-)365 2293 y(mation)c(ab)q(out)h(the)h(RNGs)f(included)h(in)f(the)i
  999. X(pac)o(k)n(age.)j(When)c(installing)e(a)h(new)p eop
  1000. X%%Page: 24 27
  1001. Xbop 262 162 a Fi(6)41 b(ADDING)13 b(NEW)h(RNGS)f(TO)h(THE)g(P)m(A)o(CKA)o(GE)
  1002. X507 b Fl(24)324 291 y Ff(INCS)21 b(=)g(mrandom.h)f(bentley.h)g(pcrand.h)g
  1003. X(ran0.h)h(ran1.h)f(ran2.h)324 341 y(ultra.h)g(xsq.h)h(myrng.h)324
  1004. X391 y(SRCS)g(=)g(mrtest.c)f(mrandom.c)g(bentley.c)g(pcrand.c)g(ran0.c)h
  1005. X(ran1.c)324 440 y(ran2.c)f(ultra.c)h(xsq.c)f(myrng.c)324 490
  1006. Xy(OBJS)h(=)g(mrandom.o)f(bentley.o)g(pcrand.o)g(ran0.o)h(ran1.o)f(ran2.o)324
  1007. X540 y(ultra.o)g(xsq.o)h(myrng.o)592 631 y Fl(Figure)14 b(12:)j(Addition)c(of)
  1008. Xh Ff(myrng)e Fl(to)i Ff(makefile)365 765 y Fl(RNG,)f(the)i(appropriate)g
  1009. XFf(#define)p Fl(d)d(v)n(alues)i(need)i(to)e(b)q(e)h(inserted)g(at)f(the)h
  1010. X(end)g(of)365 814 y(eac)o(h)k(initialization)d(list.)31 b(F)m(or)17
  1011. Xb(example,)h(the)h(declaration)f(of)g Ff(RNGname)p 1571 814
  1012. X14 2 v 14 w(a)g Fl(cur-)365 864 y(ren)o(tly)c(reads:)428 980
  1013. Xy Ff(char)21 b(RNGname)p 694 980 V 14 w(a[NUM)p 818 980 V 14
  1014. Xw(RNGS][RNGIDSTRLEN]=)o({RNGn)o(ame)p 1423 980 V 13 w(0,)g(RNGname)p
  1015. X1656 980 V 14 w(1,)455 1030 y(RNGname)p 612 1030 V 14 w(2,)g(RNGname)p
  1016. X845 1030 V 14 w(3,)h(RNGname)p 1079 1030 V 14 w(4,)f(RNGname)p
  1017. X1312 1030 V 15 w(5,)g(RNGname)p 1546 1030 V 14 w(6,)455 1080
  1018. Xy(RNGname)p 612 1080 V 14 w(7,)g(RNGname)p 845 1080 V 14 w(8,)h(RNGname)p
  1019. X1079 1080 V 14 w(9};)365 1196 y Fl(After)15 b(adding)e(a)g(new)i(RNG)e(to)h
  1020. X(the)g(pac)o(k)n(age,)f(this)h(declaration)g(w)o(ould)f(read:)428
  1021. X1312 y Ff(char)21 b(RNGname)p 694 1312 V 14 w(a[NUM_RNGS][RNGI)o(DSTRL)o
  1022. X(EN]={)o(RNGna)o(me)p 1430 1312 V 13 w(0,)g(RNGname)p 1662
  1023. X1312 V 14 w(1,)455 1362 y(RNGname)p 612 1362 V 14 w(2,)g(RNGname)p
  1024. X845 1362 V 14 w(3,)h(RNGname)p 1079 1362 V 14 w(4,)f(RNGname)p
  1025. X1312 1362 V 15 w(5,)g(RNGname)p 1546 1362 V 14 w(6,)455 1412
  1026. Xy(RNGname)p 612 1412 V 14 w(7,)g(RNGname)p 845 1412 V 14 w(8,)h(RNGname)p
  1027. X1079 1412 V 14 w(9,)455 1461 y(/*)f(RNG)g(#10)g(added)g(->)g(*/)h(RNGname)p
  1028. X1113 1461 V 14 w(10};)365 1578 y Fl(The)13 b(arra)o(ys)f Ff(statesize)p
  1029. X773 1578 V 13 w(a)p Fl(,)g Ff(seedsize)p 1008 1578 V 14 w(a)p
  1030. XFl(,)g Ff(range)p 1178 1578 V 14 w(a)p Fl(,)g Ff(returns)p
  1031. X1392 1578 V 14 w(a)p Fl(,)f Ff(statetype)p 1649 1578 V 14 w(a)p
  1032. XFl(,)365 1627 y Ff(seed)p 456 1627 V 15 w(a)p Fl(,)i Ff(dgen)p
  1033. X606 1627 V 15 w(a)p Fl(,)g Ff(lgen)p 756 1627 V 15 w(a)p Fl(,)g(and)h
  1034. XFf(check)p 1009 1627 V 15 w(a)f Fl(need)i(to)f(b)q(e)g(similarly)d(mo)q
  1035. X(di\014ed.)262 1743 y Fd(6.4)55 b(Remaking)16 b(the)j(mrandom)d(P)n(ac)n(k)m
  1036. X(age)262 1820 y Fl(Once)21 b(y)o(ou)f(ha)o(v)o(e)f(added)i(an)f(RNG)f(to)h
  1037. X(the)h(pac)o(k)n(age)f(as)g(describ)q(ed)i(in)e(the)g(previous)262
  1038. X1870 y(sections,)14 b(y)o(ou)f(will)g(need)i(to)e(remak)o(e)h(the)g(mrandom)d
  1039. X(pac)o(k)n(age.)18 b(T)m(o)13 b(do)g(this:)324 1952 y Fe(\017)20
  1040. Xb Fl(Mak)o(e)11 b(sure)h(that)f(all)f(of)h(the)g(\014les)h(for)e(the)i
  1041. X(mrandom)c(pac)o(k)n(age,)j(include)g(the)g(source)365 2002
  1042. Xy(and)j(header)h(\014les)f(for)g(y)o(our)f(new)i(RNG,)d(are)j(in)e(the)i
  1043. X(same)e(directory)m(.)324 2085 y Fe(\017)20 b Fl(Include)d(the)f(names)f(of)g
  1044. X(y)o(our)h(header,)g(source,)i(and)d(ob)r(ject)i(\014les)f(in)f(`)p
  1045. XFf(makefile)p Fl(')365 2135 y(on)e(the)h(lines)f(lab)q(eled)g
  1046. XFf(INCS)p Fl(,)e Ff(SRCS)p Fl(,)h(and)h Ff(OBJS)p Fl(,)f(resp)q(ectiv)o(ely)m
  1047. X(,)i(as)f(sho)o(w)g(in)f(Figure)365 2184 y(12.)324 2267 y Fe(\017)20
  1048. Xb Fl(F)m(ollo)o(w)12 b(the)i(instructions)g(for)f(making)e(the)j(mrandom)d
  1049. X(pac)o(k)n(age,)h(as)i(describ)q(ed)h(in)365 2317 y(Section)g(3.)262
  1050. X2399 y(Once)d(the)g(pac)o(k)n(age)f(has)h(b)q(een)h(remade)e(it)g(will)f(b)q
  1051. X(e)i(ready)g(for)f(use,)h(with)g(y)o(our)f(new)h(RNG,)262 2449
  1052. Xy(b)o(y)h(other)i(programs.)p eop
  1053. X%%Page: 25 28
  1054. Xbop 262 162 a Fi(A)41 b(THE)14 b(RNGD)o(A)m(T)m(A)e(STR)o(UCTURE)727
  1055. Xb Fl(25)262 307 y Fk(A)68 b(The)23 b(RNGdata)g(Structure)262
  1056. X406 y Fd(A.1)55 b(In)n(tro)r(duction)262 483 y Fl(This)15 b(section)h
  1057. X(describ)q(es)i(the)e(represen)o(tation)h(in)e(C)h(of)f(the)h
  1058. XFf(RNGdata)e Fl(structure)k(whic)o(h)262 533 y(is)12 b(used)i(b)o(y)e(the)i
  1059. X(mrandom)c(pac)o(k)n(age)i(to)h(represen)o(t)i(RNGs.)i(This)c(structure)i
  1060. X(need)f(nev)o(er)262 583 y(b)q(e)j(manipulated)d(b)o(y)j(the)g(programmer,)e
  1061. X(except)j(as)f(describ)q(ed)h(in)e(Section)h(6.1.)26 b(This)262
  1062. X632 y(section,)17 b(therefore,)i(is)e(in)o(tended)g(for)g(those)g(who)g(are)g
  1063. X(in)o(terested)i(in)d(learning)h(a)f(little)262 682 y(more)c(ab)q(out)i(the)h
  1064. X(inner)f(w)o(orkings)f(of)g(the)i(mrandom)c(pac)o(k)n(age.)324
  1065. X732 y(In)j(order)i(to)e(generate)i(random)d(n)o(um)o(b)q(ers,)h(the)h(user)h
  1066. X(m)o(ust)d(\014rst)j(declare)f(a)f(p)q(oin)o(ter)262 782 y(to)f(an)h
  1067. XFf(RNGdata)f Fl(structure,)j(and)d(use)i Ff(init_rng)e Fl(to)h(allo)q(cate)f
  1068. X(space)i(for)f(the)h(RNG)e(and)262 832 y(p)q(erform)8 b(v)n(arious)i
  1069. X(initialization)d(functions.)16 b(The)10 b(user)h(uses)g(the)g(RNG)e(en)o
  1070. X(tirely)h(through)262 882 y(calls)i(pro)o(vided)i(b)o(y)f(the)h(in)o(terface)
  1071. Xf(describ)q(ed)i(in)e(Section)h(5.4;)e(i.e.)17 b(the)d(user)h(should)e(not)
  1072. X262 931 y(directly)h(manipulate)d(the)k Ff(RNGdata)d Fl(structure.)262
  1073. X1048 y Fd(A.2)55 b(Inside)19 b(the)f(Structure)262 1124 y Fl(The)c
  1074. X(de\014nition)f(of)h(the)g Ff(RNGdata)e Fl(structure)17 b(is)c(displa)o(y)o
  1075. X(ed)h(in)f(Figure)h(13.)324 1174 y(Descriptions)g(of)g(its)f(\014elds)i(are)f
  1076. X(as)g(follo)o(ws:)262 1265 y Ff(rngalg)19 b Fl(A)f(n)o(um)o(b)q(er)g(iden)o
  1077. X(tifying)f(the)i(algorithm)d(to)i(b)q(e)h(used)g(b)o(y)f(the)h(RNG)f(to)g
  1078. X(pro-)365 1315 y(duce)f(pseudorandom)e(generates.)25 b(Algorithms)13
  1079. Xb(in)i(the)i(pac)o(k)n(age)e(are)h(n)o(um)o(b)q(ered)365 1365
  1080. Xy(sequen)o(tially)h(starting)f(with)h(0;)g(curren)o(tly)h(there)g(are)f(10)f
  1081. X(algorithms)f(installed,)365 1415 y(n)o(um)o(b)q(ered)f(0)g(through)h(9.)k(A)
  1082. X14 b(table)h(of)e(RNGs)h(whic)o(h)g(are)h(curren)o(tly)g(installed)f(in)365
  1083. X1465 y(the)h(mrandom)10 b(pac)o(k)n(age,)j(with)h(their)g(corresp)q(onding)g
  1084. X(algorithm)e(n)o(um)o(b)q(ers,)g(is)i(in)365 1514 y(App)q(endix)h(B.)262
  1085. X1597 y Ff(mrandom_alg)j Fl(The)12 b(algorithm)d(use)j(b)o(y)g
  1086. XFf(mrandomrv)d Fl(when)j(called)g(with)f(this)g(RNG.)g(See)365
  1087. X1647 y(Section)k(5.4.2)d(for)h(more)g(on)h Ff(mrandomrv)p Fl(.)262
  1088. X1730 y Ff(rngstate)19 b Fl(A)14 b(p)q(oin)o(ter)g(to)g(the)g(RNG's)g(state)g
  1089. X(v)o(ector,)h(used)g(to)f(store)h(the)f(curren)o(t)i(state)365
  1090. X1780 y(of)i(the)g(RNG.)f(See)h(Sections)h(5.4.3,)d(6.1,)i(and)f(6.2.1)g(for)g
  1091. X(more)g(information)e(on)365 1830 y(RNG)e(state)i(v)o(ectors.)262
  1092. X1913 y Ff(rngseed)k Fl(A)14 b(p)q(oin)o(ter)f(to)h(the)g(RNG's)f(seed)i(v)o
  1093. X(ector.)k(See)14 b(Section)h(5.4.4)c(for)j(more)f(infor-)365
  1094. X1963 y(mation)f(on)i(RNG)f(seed)i(v)o(ectors.)262 2046 y Ff(rngcount1)p
  1095. XFh(,)f Ff(rngcount2)19 b Fl(These)12 b(t)o(w)o(o)f(v)n(alues)g(represen)o(t)i
  1096. X(the)f(n)o(um)o(b)q(er)f(of)f(generates)j(the)365 2096 y(RNG)g(has)h(pro)q
  1097. X(duced)i(since)e(initialization,)d(according)j(to)g(the)g(form)o(ula:)428
  1098. X2212 y Ff(rngcount1+rngco)o(unt2*)o(BILLI)o(ON)365 2328 y Fl(where)21
  1099. Xb(BILLION)e(is)g(de\014ned)h(in)f(`)p Ff(mrandom.h)p Fl('.)31
  1100. Xb(Please)20 b(note)f(that)h(the)f(v)n(alue)365 2378 y(represen)o(ted)14
  1101. Xb(b)o(y)e Ff(rngcount1)d Fl(and)i Ff(rngcount2)f Fl(is)h(the)h
  1102. XFc(total)f Fl(n)o(um)o(b)q(er)f(of)h(generates)365 2428 y(pro)q(duced)17
  1103. Xb(b)o(y)f(the)g(RNG)f(since)h(initialization,)d(including)i(those)h
  1104. X(discarded)h(due)p eop
  1105. X%%Page: 26 29
  1106. Xbop 262 162 a Fi(A)41 b(THE)14 b(RNGD)o(A)m(T)m(A)e(STR)o(UCTURE)727
  1107. Xb Fl(26)262 702 y Ff(struct)42 b(rngdata)20 b({)414 752 y(long)h(rngalg;)414
  1108. X802 y(long)g(mrandom_alg;)414 852 y(long)g(*rngstate;)414 902
  1109. Xy(long)g(*rngseed;)414 952 y(long)g(rngcount1;)414 1001 y(long)g(rngcount2;)
  1110. X414 1051 y(struct)g({)610 1101 y(long)g(size;)610 1151 y(long)g(nleft;)610
  1111. X1201 y(long)g(nbleft;)610 1250 y(double)g(*dbuf,*dbufp;)610
  1112. X1300 y(long)g(*lbuf,*lbufp;)610 1350 y(int)g(*bbuf,*bbufp;)610
  1113. X1400 y(})h(buffer;)414 1450 y(long)f(rngnextval;)414 1499 y(long)g(rngsplit;)
  1114. X414 1549 y(char)g(rngname[];)414 1599 y(long)g(rngstatesize;)414
  1115. X1649 y(long)g(rngseedsize;)414 1699 y(long)g(rngrangem1;)414
  1116. X1749 y(double)g(rngrange;)414 1798 y(signed)g(int)g(rngreturns;)262
  1117. X1848 y(};)262 1898 y(typedef)f(struct)g(rngdata)h(RNGdata;)668
  1118. X2081 y Fl(Figure)14 b(13:)k(The)c Ff(RNGdata)f Fl(structure)p
  1119. Xeop
  1120. X%%Page: 27 30
  1121. Xbop 262 162 a Fi(B)41 b(RNGS)14 b(CURRENTL)m(Y)f(INST)m(ALLED)g(IN)h(THE)g(P)
  1122. Xm(A)o(CKA)o(GE)286 b Fl(27)365 307 y(to)18 b(splitting)f(of)g(the)i(RNG.)d
  1123. X(\(See)j(Section)f(5.4.7)e(for)i(more)f(information)e(ab)q(out)365
  1124. X357 y(splitting)e(RNGs.\))262 440 y Ff(rngnextval)18 b Fl(The)h(next)f(v)n
  1125. X(alue)g(to)g(b)q(e)g(output)h(from)d(the)j(RNG.)d(This)i(v)n(alue)g(is)g
  1126. X(used)365 490 y(in)o(ternally)13 b(b)o(y)h(the)g(mrandom)d(library)i(and)h
  1127. X(is)g(not)g(guaran)o(teed)g(to)g(b)q(e)g(accurate.)262 573
  1128. Xy Ff(rngsplit)19 b Fl(Ev)o(ery)10 b(\()p Ff(split)p Fl(+1\)-th)g(generate)h
  1129. X(of)f(the)h(underlying)f(RNG)f(will)g(b)q(e)i(returned)365
  1130. X623 y(b)o(y)k(the)h(RNG)e(calling)f(pro)q(cedures.)24 b Ff(rngsplit)13
  1131. Xb Fl(is)i(set)h(to)f Ff(DEF_SPLIT)e Fl(up)q(on)i(ini-)365 672
  1132. Xy(tialization)g(of)h(the)h(RNG,)e(as)i(de\014ned)h(in)e(`)p
  1133. XFf(mrandom.h)p Fl('.)23 b(See)17 b(Section)g(5.4.7)e(for)365
  1134. X722 y(more)e(information)e(ab)q(out)j(splitting)f(RNGs.)262
  1135. X805 y Ff(buffer)19 b Fl(This)g(structure)j(con)o(tains)d(information)e(ab)q
  1136. X(out)i(the)h(RNG's)f(bu\013er)h(and)g(its)365 855 y(bit)c(bu\013er.)27
  1137. Xb(\(See)17 b(Section)g(5.4.2)e(for)h(more)f(information)f(on)i(RNG)f
  1138. X(bu\013ers.\))28 b(It)365 905 y(con)o(tains)14 b(sev)o(eral)h(\014elds:)365
  1139. X988 y Ff(size)20 b Fl(The)15 b(n)o(um)o(b)q(er)e(of)g(en)o(tries)i(in)e(the)i
  1140. X(RNG's)e(bu\013er.)365 1054 y Ff(nleft)20 b Fl(The)14 b(n)o(um)o(b)q(er)g(of)
  1141. Xf(v)n(alues)g(left)h(in)f(the)i(RNG's)e(bu\013er.)365 1121
  1142. Xy Ff(nbleft)20 b Fl(The)14 b(n)o(um)o(b)q(er)f(of)h(v)n(alues)f(left)h(in)f
  1143. X(the)i(RNG's)e(bit)g(bu\013er.)365 1187 y Ff(dbuf)p Fh(,)j
  1144. XFf(dbufp)j Fl(A)10 b(p)q(oin)o(ter)g(to)f(the)h(\014rst)h(en)o(try)f(in)f
  1145. X(the)h(double)g(bu\013er,)h(and)e(a)g(p)q(oin)o(ter)457 1237
  1146. Xy(to)k(the)i(next)f(en)o(try)h(to)e(b)q(e)i(retriev)o(ed)g(from)d(the)j
  1147. X(double)f(bu\013er.)365 1303 y Ff(lbuf)p Fh(,)i Ff(lbufp)j
  1148. XFl(Same)13 b(for)h(the)g(long)f(bu\013er.)365 1370 y Ff(bbuf)p
  1149. XFh(,)j Ff(bbufp)j Fl(Same)13 b(for)h(the)g(bit)g(bu\013er.)324
  1150. X1461 y(The)e(remaining)d(v)n(alues)i(in)g(the)i(RNGdata)d(structure)k(are)e
  1151. X(deriv)o(ed)g(from)d(the)j(RNG's)262 1511 y(header)e(\014le)g(up)q(on)g
  1152. X(initialization.)k(F)m(or)c(more)e(information)f(on)j(the)g(v)n(alues)g(of)f
  1153. X(these)j(\014elds,)262 1561 y(see)j(Section)f(6.2.1.)262 1698
  1154. Xy Fk(B)68 b(RNGs)23 b(Curren)n(tly)f(Installed)f(in)h(the)h(P)n(ac)n(k)l(age)
  1155. X262 1789 y Fl(There)11 b(are)g(curren)o(tly)g(ten)g(RNGs)f(installed)g(in)g
  1156. X(the)h(mrandom)d(pac)o(k)n(age.)16 b(This)11 b(app)q(endix)262
  1157. X1839 y(pro)o(vides)16 b(brief)g(descriptions)h(of)f(eac)o(h)g(of)g(them.)24
  1158. Xb(References)18 b(are)f(pro)o(vided)f(for)g(those)262 1889
  1159. Xy(who)d(are)h(in)o(terested)i(in)d(\014nding)h(out)g(ab)q(out)f(the)i(RNGs)e
  1160. X(in)h(more)f(detail.)262 1980 y Fh(RNG)i(algorithm)e(0:)21
  1161. Xb(A)16 b(trivial)e(RNG)20 b Fl(A)14 b(trivial)f(RNG)h(is)g(included)g(in)g
  1162. X(the)h(pac)o(k-)365 2030 y(age,)20 b(primarily)c(for)i(testing)i(purp)q
  1163. X(oses.)34 b(The)19 b(generates)i(it)d(pro)q(duces)i(are)g(not)365
  1164. X2080 y(\\random")c(in)h(virtually)e(an)o(y)i(sense)i(of)e(the)h(w)o(ord;)h
  1165. X(it)e(simply)e(pro)q(duces)k(gener-)365 2129 y(ates)c(from)d(an)i
  1166. X(arithmetical)e(progression)i(determined)g(b)o(y)g(its)g(initial)e(seeds.)20
  1167. Xb(F)m(or)365 2179 y(example,)f(if)g(it)g(is)g(seeded)i(with)e(5)g(and)g(7,)h
  1168. X(resp)q(ectiv)o(ely)m(,)i(it)d(will)e(pro)q(duce)k(the)365
  1169. X2229 y(sequence)16 b(5,)d(12,)g(19,)g(26,)g(etc.)365 2295 y(This)h(RNG)f(tak)
  1170. Xo(es)h(t)o(w)o(o)g Ff(long)p Fl(s)f(as)h(seeds.)20 b(It)14
  1171. Xb(returns)h(generates)h(of)d(t)o(yp)q(e)i Ff(long)p Fl(.)262
  1172. X2378 y Fh(RNG)g(algorithm)e(1:)21 b(4.3bsd)15 b(random)k Fl(This)g(is)g(UNIX)
  1173. Xg(4.3bsd)f Ff(random)p Fl(.)31 b(It)19 b(is)g(a)365 2428 y(31-bit)f
  1174. X(nonlinear)g(additiv)o(e)g(feedbac)o(k)h(generator)h(with)e(a)g(range)h(of)f
  1175. X(2)1534 2413 y Fb(31)1587 2428 y Fl(and)h(a)p eop
  1176. X%%Page: 28 31
  1177. Xbop 262 162 a Fi(B)41 b(RNGS)14 b(CURRENTL)m(Y)f(INST)m(ALLED)g(IN)h(THE)g(P)
  1178. Xm(A)o(CKA)o(GE)286 b Fl(28)365 307 y(p)q(erio)q(d)19 b(of)f(appro)o(ximately)
  1179. Xe(16)c Fe(\003)g Fl(2)937 292 y Fb(31)984 307 y Fe(\000)g Fl(1.)32
  1180. Xb(It)18 b(is)h(nominall)o(y)d(able)i(to)g(sa)o(v)o(e)h(and)365
  1181. X357 y(restore)g(state,)f(but)f(its)g(state-sa)o(ving)g(co)q(de)h(is)f(buggy)m
  1182. X(.)27 b(Therefore,)18 b(when)g(using)365 407 y Ff(random)e
  1183. XFl(with)g(the)i(mrandom)13 b(pac)o(k)n(age,)k(no)g(more)e(than)i(one)g(RNG)f
  1184. X(should)h(use)365 457 y Ff(random)c Fl(at)h(a)f(time.)365 522
  1185. Xy(This)f(RNG)e(tak)o(es)i(a)f(single)g Ff(long)f Fl(as)i(a)f(seed.)18
  1186. Xb(It)12 b(returns)g(generates)h(of)e(t)o(yp)q(e)h Ff(long)p
  1187. XFl(.)262 604 y Fh(RNG)j(algorithm)e(2:)21 b(the)15 b(Kn)o(uth/Ben)o(tl)o(ey)e
  1188. X(prand)19 b Fl(This)10 b(lagged-Fib)q(onacci)e(RNG)365 654
  1189. Xy(w)o(as)16 b(in)o(tro)q(duced)h(b)o(y)e(Jon)h(Ben)o(tley)h(in)f(his)f
  1190. X(\\Soft)o(w)o(are)h(Exploratorium")d(column)365 704 y(in)19
  1191. Xb Fc(Unix)g(R)n(eview)p Fl(,)g(V)m(ol.)32 b(10,)18 b(No.)33
  1192. Xb(6,)19 b(June)h(1992,)e(and)g(is)h(based)g(on)g(one)g(\014rst)365
  1193. X754 y(presen)o(ted)d(in)d(Donald)f(E.)h(Kn)o(uth's)h Fc(The)h(A)o(rt)e(of)i
  1194. X(Computer)f(Pr)n(o)n(gr)n(amming)p Fl(,)e(V)m(ol.)365 803 y(2,)g(Addison-W)m
  1195. X(esley)m(,)g(Reading,)f(Mass.,)i(1981.)j(It)d(has)g(a)f(range)h(of)f
  1196. X(1,000,000,00)o(0.)365 869 y(This)g(RNG)e(tak)o(es)i(a)f(single)g
  1197. XFf(long)f Fl(as)i(a)f(seed.)18 b(It)12 b(returns)g(generates)h(of)e(t)o(yp)q
  1198. X(e)h Ff(long)p Fl(.)262 951 y Fh(RNG)j(algorithm)e(3:)21 b(The)16
  1199. Xb(P)o(ortable)d(Com)o(bined)g(RNG)21 b Fl(This)11 b(com)o(bined)f(prime)365
  1200. X1001 y(m)o(ultiplicativ)o(e)i(congruen)o(tial)i(RNG)f(w)o(as)h(dev)o(elop)q
  1201. X(ed)h(based)h(on)e(algorithms)e(and)365 1050 y(selections)20
  1202. Xb(of)e(prime)g(n)o(um)o(b)q(ers)h(presen)o(ted)i(in)d(\\E\016cien)o(t)h(and)g
  1203. X(P)o(ortable)f(Com-)365 1100 y(bined)h(Random)d(Num)o(b)q(er)i(Generators,")h
  1204. X(Pierre)h(L'Ecuy)o(er,)f Fc(Communic)n(ations)365 1150 y(of)g(the)h(A)o(CM)p
  1205. XFl(,)e(V)m(ol.)31 b(10,)19 b(No.)32 b(6,)19 b(June)h(1992,)e(and)g(\\Random)f
  1206. X(Num)o(b)q(er)h(Gen-)365 1200 y(erators:)24 b(Go)q(o)q(d)15
  1207. Xb(Ones)i(are)g(Hard)f(to)g(Find,")f(Stephen)i(P)o(ark)f(and)g(Keith)h
  1208. X(Miller,)365 1250 y Fc(Communic)n(ations)h(of)g(the)f(A)o(CM)p
  1209. XFl(,)f(V)m(ol.)25 b(31,)17 b(No.)26 b(10,)17 b(Octob)q(er)h(1992.)25
  1210. Xb(It)17 b(has)g(a)365 1299 y(range)d(of)g(2147483561.)365 1365
  1211. Xy(This)g(RNG)f(tak)o(es)h(t)o(w)o(o)g Ff(long)p Fl(s)f(as)h(seeds.)20
  1212. Xb(It)14 b(returns)h(generates)h(of)d(t)o(yp)q(e)i Ff(long)p
  1213. XFl(.)262 1447 y Fh(RNG)g(algorithm)e(4:)21 b(4.3bsd)15 b(nrand48)k
  1214. XFl(This)14 b(is)g(UNIX)g(4.3bsd)f Ff(nrand48)p Fl(.)k(It)d(pro-)365
  1215. X1497 y(duces)k(generates)g(using)f(a)f(linear)g(congruen)o(tial)g(algorithm)e
  1216. X(and)j(48-bit)e(in)o(teger)365 1547 y(arithmetic.)i(It)d(has)g(a)g(range)g
  1217. X(of)f(2)917 1531 y Fb(31)952 1547 y Fl(.)365 1612 y(This)g(RNG)f(tak)o(es)h
  1218. X(three)h Ff(unsigned)20 b(short)p Fl(s)12 b(as)h(seeds.)19
  1219. Xb(They)13 b(are)g(passed)h(to)e(the)365 1662 y(seeding)i(pro)q(cedure)h(as)e
  1220. X(t)o(w)o(o)g Ff(long)p Fl(s,)f(and)h(are)g(in)o(terpreted)i(in)e(the)g(follo)
  1221. Xo(wing)e(w)o(a)o(y:)415 1744 y Fe(\017)21 b Fl(The)14 b(16)f(least)h
  1222. X(signi\014can)o(t)g(bits)g(of)f(the)i(second)f Ff(long)g Fl(is)f(the)i
  1223. X(\014rst)f(seed.)415 1809 y Fe(\017)21 b Fl(The)14 b(16)f(least)h
  1224. X(signi\014can)o(t)g(bits)g(of)f(the)i(\014rst)f Ff(long)f Fl(is)h(the)g
  1225. X(second)h(seed.)415 1874 y Fe(\017)21 b Fl(The)14 b(16)f(most)g(signi\014can)
  1226. Xo(t)g(bits)h(of)g(the)g(\014rst)h Ff(long)e Fl(is)h(the)g(third)g(seed.)415
  1227. X1939 y Fe(\017)21 b Fl(The)14 b(16)f(most)g(signi\014can)o(t)g(bits)h(of)g
  1228. X(the)g(second)h Ff(long)e Fl(is)h(ignored.)365 2021 y(This)g(RNG)f(returns)j
  1229. X(generates)f(of)e(t)o(yp)q(e)i Ff(long)p Fl(.)262 2102 y Fh(RNG)g(algorithm)e
  1230. X(5:)21 b(4.3bsd)15 b(rand)20 b Fl(This)15 b(is)f(UNIX)h(4.3bsd)g
  1231. XFf(rand)p Fl(.)k(It)c(uses)h(a)f(m)o(ul-)365 2152 y(tiplicativ)o(e)g
  1232. X(congruen)o(tial)h(algorithm.)22 b(It)16 b(has)g(a)g(p)q(erio)q(d)h(of)e(2)
  1233. X1374 2137 y Fb(32)1425 2152 y Fl(and)h(a)g(range)g(of)365 2202
  1234. Xy(2)386 2187 y Fb(31)421 2202 y Fl(.)365 2268 y(This)c(RNG)e(tak)o(es)i(a)f
  1235. X(single)g Ff(long)f Fl(as)i(a)f(seed.)18 b(It)12 b(returns)g(generates)h(of)e
  1236. X(t)o(yp)q(e)h Ff(long)p Fl(.)262 2350 y Fh(RNG)j(algorithm)e(6,)j(7,)g(and)f
  1237. X(8:)22 b(Press)14 b(and)i(T)l(euk)o(olsky's)e(ran0,)i(ran1,)f(and)g(ran2)365
  1238. X2399 y Fl(These)d(three)h(m)o(ultipli)o(cativ)o(e)8 b(congruen)o(tial)j(RNGs)
  1239. Xf(are)h(adapted)g(from)e(those)j(pre-)365 2449 y(sen)o(ted)k(in)d(\\P)o
  1240. X(ortable)h(Random)d(Num)o(b)q(er)j(Generators,")g(William)c(H.)j(Press)j(and)
  1241. Xp eop
  1242. X%%Page: 29 32
  1243. Xbop 262 162 a Fi(B)41 b(RNGS)14 b(CURRENTL)m(Y)f(INST)m(ALLED)g(IN)h(THE)g(P)
  1244. Xm(A)o(CKA)o(GE)286 b Fl(29)365 307 y(Saul)15 b(A.)h(T)m(euk)o(olsky)m(,)e
  1245. XFc(Computers)j(in)f(Physics)p Fl(,)g(V)m(ol.)23 b(6,)15 b(No.)24
  1246. Xb(5,)15 b(Sep/Oct)i(1992.)365 357 y(They)f(all)e(ha)o(v)o(e)i(a)f(p)q(erio)q
  1247. X(d)h(of)f(2)868 342 y Fb(31)913 357 y Fe(\000)10 b Fl(2)16
  1248. Xb(and)f(a)g(range)h(of)f(2)1295 342 y Fb(31)1340 357 y Fe(\000)10
  1249. Xb Fl(1.)46 b(These)17 b(RNGs)365 407 y(tak)o(e)d(a)g(single)f
  1250. XFf(long)g Fl(as)h(a)g(seed.)19 b(They)14 b(return)i(generates)f(of)e(t)o(yp)q
  1251. X(e)i Ff(double)p Fl(.)262 490 y Fh(RNG)g(algorithm)e(9:)21
  1252. Xb(Marsaglia's)15 b(Ultra)g(RNG)20 b Fl(W)m(e)12 b(obtained)h(the)h(source)g
  1253. X(co)q(de)365 540 y(for)19 b(this)h(generator)g(b)o(y)f(anon)o(ymous)e(ftp)j
  1254. X(from)d Ff(nic.funit.fi)g Fl(\(tak)o(e)j(the)g(\014le)365 589
  1255. Xy Ff(fsultra.zip)e Fl(from)h(the)h(directory)h Ff(/pub/msdos/science/)o
  1256. X(math/)o(fsult)o(ra)p Fl(\).)365 639 y(A)e(note)g(in)f(the)h(`)p
  1257. XFf(readme)p Fl(')e(\014le)i(sa)o(ys:)27 b(\\T)m(o)18 b(obtain)g(p)q
  1258. X(ermission)g(to)g(incorp)q(orate)365 689 y(this)d(program)d(in)o(to)i(an)o(y)
  1259. Xg(commercial)d(pro)q(duct,)k(please)g(con)o(tact)g(the)g(authors)g(at)365
  1260. X739 y(the)i(e-mail)c(address)18 b(giv)o(en)d(ab)q(o)o(v)o(e)h
  1261. X([a\014r@stat.fsu.edu)g(or)g(geo@stat.fsu.edu])g(or)365 789
  1262. Xy(at)g(Departmen)o(t)g(of)g(Statistics)h(and)f(Sup)q(ercomputer)h
  1263. X(Computations)d(Researc)o(h)365 839 y(Institute,)20 b(Florida)d(State)i(Univ)
  1264. Xo(ersit)o(y)m(,)f(T)m(allahassee,)g(FL)g(32306.")29 b(This)18
  1265. Xb(RNG)365 888 y(is)d(one)g(of)e(those)j(originally)c(presen)o(ted)17
  1266. Xb(in)d(\\A)g(New)h(Class)g(of)f(Random)e(Num)o(b)q(er)365 938
  1267. Xy(Generators,")18 b(George)f(Marsaglia)f(and)g(Arif)h(Zaman,)e
  1268. XFc(The)j(A)o(nnals)f(of)h(Applie)n(d)365 988 y(Pr)n(ob)n(ability)p
  1269. XFl(,)13 b(V)m(ol.)k(1,)c(No.)18 b(3,)13 b(1991.)k(It)d(is)g(a)g
  1270. X(\\subtract-with-b)q(orro)o(w")g(generator)365 1038 y(with)g(a)f(range)i(of)e
  1271. X(2)676 1023 y Fb(32)725 1038 y Fl(and)g(a)h(staggering)g(p)q(erio)q(d)g(of)f
  1272. X(10)1257 1023 y Fb(354)1308 1038 y Fl(.)365 1104 y(This)18
  1273. Xb(RNG)f(tak)o(es)i(t)o(w)o(o)e Ff(unsigned)j(long)p Fl(s)e(as)g(seeds.)32
  1274. Xb(It)18 b(returns)i(generates)f(of)365 1154 y(t)o(yp)q(e)c
  1275. XFf(double)p Fl(.)p eop
  1276. X%%Trailer
  1277. Xend
  1278. Xuserdict /end-hook known{end-hook}if
  1279. X%%EOF
  1280. END_OF_FILE
  1281. if test 85170 -ne `wc -c <'doc/mrandom.ps.2'`; then
  1282.     echo shar: \"'doc/mrandom.ps.2'\" unpacked with wrong size!
  1283. fi
  1284. # end of 'doc/mrandom.ps.2'
  1285. fi
  1286. echo shar: End of archive 5 \(of 6\).
  1287. cp /dev/null ark5isdone
  1288. MISSING=""
  1289. for I in 1 2 3 4 5 6 ; do
  1290.     if test ! -f ark${I}isdone ; then
  1291.     MISSING="${MISSING} ${I}"
  1292.     fi
  1293. done
  1294. if test "${MISSING}" = "" ; then
  1295.     echo You have unpacked all 6 archives.
  1296.     rm -f ark[1-9]isdone
  1297. else
  1298.     echo You still need to unpack the following archives:
  1299.     echo "        " ${MISSING}
  1300. fi
  1301. ##  End of shell archive.
  1302. exit 0
  1303.