Article View: comp.sys.amiga.tech
Article #1250Re: ARexx psuedo-random number generator
From: Mike (I'll think of something ye...
Date: Wed, 13 Sep 1989 03:23
Date: Wed, 13 Sep 1989 03:23
59 lines
3404 bytes
3404 bytes
In article <19504@unix.cis.pitt.edu> ejkst@unix.cis.pitt.edu (Eric J. Kennedy) writes:
<I was having a little trouble with ARexx's random number generator, so I
<performed the following small test. The 1 to 45 range is the range in my
<application, so I kept it for the test. I'm using the time in seconds as the
<seed, which strikes me as being the most variable easily obtainable number.
Your use of the random number generator is incorrect. You should only
initialize it once. Typical output from a version that doesn't do that
(with performance tweaks, and output changed to self-format and be
runnable from inside of mg) is shown below.
As a general rule, serious applications should never use the random
number generator provided with a language. You should either use one
from a "known-good" library (i.e. - IMSL, if there's a random number
generator in it), or roll your own. Rolling your own can be done in an
afternoon, including chasing down and reading the references. Knuth's
"The Art of Computer Programming" vol. 2 - "Seminumerical Algorithms"
- is the canonical reference, and has lots of theory plus various
algorithms for testing random-number generators. R. G. Dromey's "How
to Solve It By Computer" (part of the Prentice-Hall International
Series in CS, edited by C.A.R. Hoare) extracts the important part for
the do-it-yourselfer into a few pages that describe the best algorithm
from Knuth, what the parameters are, and how to choose them.
<mike
hist.=0 /* initialize array */
call random 1, 45, time('S') /* initialize random number generator */
do index=1 to 10000
r=random(1,45)
hist.r = hist.r + 1
end
out = ""
do index=1 to 45
out = out || right(index, 2) right(hist.index, 5)
if index // 4 = 0 then out = out || '0a'x
else out = out || '09'x
end
return out
1 222 2 220 3 233 4 235
5 207 6 193 7 207 8 231
9 211 10 210 11 241 12 209
13 248 14 238 15 237 16 224
17 229 18 207 19 251 20 210
21 214 22 210 23 207 24 192
25 239 26 227 27 230 28 230
29 214 30 218 31 234 32 223
33 238 34 234 35 205 36 252
37 222 38 221 39 200 40 196
41 210 42 229 43 204 44 257
45 231
--
Il brilgue: les toves lubricilleux Mike Meyer
Se gyrent en vrillant dans le guave, mwm@berkeley.edu
Enmimes sont les gougebosqueux, ucbvax!mwm
Et le momerade horsgrave. mwm@ucbjade.BITNET
Technical Details
Message-ID:
<1989Sep13.032352.10321@agate.berkeley.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!eris.berkeley.edu!mwmReferences:
<19504@unix.cis.pitt.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!eris.berkeley.edu!mwm From: mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer) Newsgroups: comp.sys.amiga.tech Subject: Re: ARexx psuedo-random number generator Keywords: ARexx Random Number Generator Message-ID: <1989Sep13.032352.10321@agate.berkeley.edu> Date: 13 Sep 89 03:23:52 GMT References: <19504@unix.cis.pitt.edu> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer) Organization: Missionaria Phonibalonica Lines: 59