Paul Rubin <no.e...@nospam.invalid> writes Re: suggestion: standardize random number generator?
> In the "Valentine Bingo" thread I tried writing an implementation and
> was surprised to see that there seems to be no random number generator
> in the gforth library. Since (AFAIK) gforth is a full featured ANS
> implementation, I infer that there's no RNG specified in the standard.
> It looks like VFX supplies something called "CHOOSE" which I guess is
> non-standard. I ended up supplying my own RNG, using a fairly poor
> algorithm that I felt was ok for a simple demo program of this nature,
> but choosing and coding a good algorithm requires knowing what you're
> doing. So it wouldn't surprise me if there's an awful lot of Forth code
> out there containing crappy RNG's.
You did not look very far? Already 'Starting Forth' had a random number
called generator, called CHOOSE, and it followed Knuth's recommendations.
Your search tells us more about gforth and VFX than it does about random
generators in relation to Forth. You should have heard about FSL and FFL
by now? Taygeta archives? CFL threads (quite a while back of course)?
Here's what a search through the iForth distribution returns:
anneal.frt(56): -- Random bit generator. Press et al, 7.4, 'Generation of Random Bits'.
gaussj.frt(2946): \ "Minimal" random number generator of Park and Miller. Returns a uniform deviate
gaussj.frt(2952): \ "Minimal" random number generator of Park and Miller with Bays-Durham shuffle
gaussj.frt(2958): \ Long period (> 2e18) random number generator of L'Ecuyer with Bays-Durham shuffle
gaussj.frt(2968): \ Returns a uniform random deviate between 0.0 and 1.0, generated by pseudo-DES
gaussj.frt(2977): : poidev ( F: mean -- r ) ( Poisson distributed random deviate )
gaussj.frt(2979): -- Return a matrix of random numbers chosen from the uniform distribution with parameters LO and HI.
gaussj.frt(2985): -- Returns a matrix of random numbers chosen from the normal distribution with parameters MU and SIGMA.
gaussj.frt(2991): -- Returns a matrix of random numbers chosen from the exponential distribution with parameter MU.
gaussj.frt(2997): -- Returns a matrix of random numbers chosen from the Poisson distribution with parameter MEAN.
kiss.frt(4): * DESCRIPTION : Fast Random Number Generator with large period
mertwist.frt(4): * DESCRIPTION : Fast Random Number Generator "Mersenne Twister: A 623-Dimensionally
Equidistributed Uniform Pseudo-Random Number Generator",
miscutil.frt(1691): CR ." RANDOMIZE \ ( -- ) (Re)initialize random number generator"
miscutil.frt(1692): CR ." RANDOM \ ( -- u ) Fairly random number (integer)"
miscutil.frt(1693): CR ." CHOOSE \ ( n -- u ) 0 <= u < n pick random number from range"
miscutil.frt(1694): CR ." FRANDOM \ ( F: -- r ) Random floating-point number < 2^31"
miscutil.frt(1695): CR ." FCHOOSE \ ( n -- ) ( F: -- ur ) 0 <= ur < r pick random number from range"
mwc256.frt(4): * DESCRIPTION : Reasonably fast Random Number Generator with large period
r250.frt(4): * DESCRIPTION : R250 Pseudo-Random number generator
ran-next.frt(25): * Knuth's recommended random number generator from TAOCP, *
ran4.frt(49): RAN4 is capable of generating 2^32 different random sequences {in a
ffl\rdg.fs(3): \ rdg - the distributed pseudo random number generator module in the ffl
ffl\rdg.fs(64): ( Distributed random generator creation, initialisation and destruction )
ffl\rdg.fs(66): : rdg-init ( x xt rdg -- = Initialise the generator with the random generator xt and its data x )
ffl\rdg.fs(73): : rdg-create ( x xt "<spaces>name" -- ; -- rdg = Create a named random generator in the dictionary with the random generator xt and its data x )
ffl\rdg.fs(78): : rdg-new ( x xt -- rdg = Create a new random generator on the heap with the random generator xt and its data x )
ffl\rdg.fs(83): : rdg-free ( rdg -- = Free the random generator from the heap )
ffl\rdg.fs(89): : rdg-gen-[0,1> ( F: -- r ; rdg -- = Generate a random number [0,1> )
ffl\rdg.fs(96): : rdg-gen-<0,1> ( F: -- r ; rdg -- = Generate a positive random number <0,1> )
ffl\rdg.fs(107): ( Random generator words )
ffl\rdg.fs(109): : rdg-uniform ( F: r1 r2 -- r3 ; rdg -- = Generate a random number with a uniform distribution in the range of [r1,r2> )
ffl\rdg.fs(121): : rdg-normal ( F: r1 r2 -- r3 ; rdg -- = Generate a random number with a normal or Gaussian distribution with mu or mean r1 and sigma or standard deviation r2 )
ffl\rdg.fs(151): : rdg-exponential ( F: r1 -- r2 ; rdg -- = Generate a random number with an exponential distribution with mu or mean r1 [>0] )
ffl\rdg.fs(152): rdg-gen-<0,1> \ look for positive random number
ffl\rdg.fs(161): : rdg-gamma ( F: r1 r2 -- r3 ; rdg -- = Generate a random number with a gamma distribution with alpha r1 [>0] and beta r2 [>0], alpha*beta = mean, alpha*beta^2 = variance )
ffl\rdg.fs(207): : rdg-beta ( F: r1 r2 -- r3 ; rdg -- = Generate a random number with a beta distribution with alpha r1 [>0] and beta r2 [>0], alpha*beta = mean, alpha*beta^2 = variance )
ffl\rdg.fs(216): : rdg-binomial ( F: r -- ; u1 rdg -- u2 = Generate a random number with a binomial distribution with probability r [0,1] and trails u1 [>=0])
ffl\rdg.fs(253): : rdg-poisson ( F: r -- ; rdg -- u = Generate a random number with a Poisson distribution with mean r [>=0] )
ffl\rdg.fs(283): : rdg-pareto ( F: r1 r2 -- r3 ; rdg -- = Generate a random number with a Pareto distribution with alpha r1 [>0] the scale parameter and r2 [>0] the shape parameter )
ffl\rdg.fs(290): : rdg-weibull ( F: r1 r2 -- r3 ; rdg -- = Generate a random number with a Weibull distribution with alpha r1 [>0] the scale parameter and beta r2 [>0] the shape parameter )
ffl\rng.fs(3): \ rng - the pseudo random number generator module in the ffl
ffl\rng.fs(39): ( rng = Pseudo random number generator module )
ffl\rng.fs(40): ( The rng module implements a pseudo random number generator; )
ffl\rng.fs(63): ( Random generator structure )
ffl\rng.fs(133): ( Random generator creation, initialisation and destruction )
ffl\rng.fs(140): : rng-create ( u "<spaces>name" -- ; -- rng = Create a named random generator in the dictionary with seed u )
ffl\rng.fs(145): : rng-new ( u -- rng = Create a new random generator on the heap with seed u )
ffl\rng.fs(150): : rng-free ( rng -- = Free the random generator from the heap )
ffl\rng.fs(155): ( Random generator words )
ffl\rng.fs(162): : rng-next-number ( rng -- n = Calculate the next pseudo random number, 32 bit )
ffl\rng.fs(180): : rng-next-float ( rng -- r = Calculate the next pseudo random float number, range [0,1> )
ffl\rng.fs(188): : rng-dump ( rng -- = Dump the random generator )
C:/dfwforth/examples/bignum/diehard.frt(51): : prng ( F: -- random# )
C:/dfwforth/examples/ent/merstwist.frt(4): * DESCRIPTION : Generate sequence of "random" numbers with a cycle of 2^19937-1
C:/dfwforth/examples/ent/test-random.frt(79): : TEST-RANDOM ( c-addr u sz TRUE=terse -- )
C:/dfwforth/examples/ent/test-random.frt(92): ['] RANDOM [IS] GENERATOR S" RANDOM"
C:/dfwforth/examples/ent/test-random.frt(93): ['] iran0 [IS] GENERATOR S" iran0"
C:/dfwforth/examples/ent/test-random.frt(94): ['] iran1 [IS] GENERATOR S" iran1"
C:/dfwforth/examples/ent/test-random.frt(95): ['] iran2 [IS] GENERATOR S" iran2"
C:/dfwforth/examples/ent/test-random.frt(96): ['] iran3 [IS] GENERATOR S" iran3"
C:/dfwforth/examples/ent/test-random.frt(97): ['] ran-KISS [IS] GENERATOR S" ran-KISS"
C:/dfwforth/examples/ent/test-random.frt(98): ['] genrand [IS] GENERATOR S" genrand"
C:/dfwforth/examples/ent/test-random.frt(99): ['] genrand_int32 [IS] GENERATOR S" genrand_int32"
C:/dfwforth/examples/ent/test-random.frt(100): ['] ran-MWC256 [IS] GENERATOR S" ran-MWC256"
C:/dfwforth/examples/ent/test-random.frt(101): ['] lcm_rand [IS] GENERATOR S" lcm_rand"
C:/dfwforth/examples/ent/test-random.frt(102): ['] r250 [IS] GENERATOR S" r250"
C:/dfwforth/examples/ent/test-random.frt(103): ['] ran-Next [IS] GENERATOR S" ran-Next"
C:/dfwforth/examples/ent/test-random.frt(104): ['] random-byte [IS] GENERATOR S" random-byte"
C:/dfwforth/examples/ent/test-random.frt(105): ['] iprng [IS] GENERATOR S" iprng"
C:/dfwforth/examples/gmpfr/alt-gmpfr/libgmp-iforth.frt(403): AliasedExtern: mpf_urandomb void __gmpf_urandomb (mpf_ptr rop, gmp_randstate_t state, mp_bitcnt_t nbits);
C:/dfwforth/examples/misc/shannon.frt(132): -- generate a pseudo-random number with a Gaussian distribution
C:/dfwforth/examples/nrc/chapter7_Random_Numbers/random.frt(4): * DESCRIPTION : Access to the random number routines in the nrclib.dll
C:/dfwforth/examples/numeric/random3.frt(4): * DESCRIPTION : super random number generator
C:/dfwforth/examples/numeric/wurstkessel.frt(5): / Wurstkessel data from
www.random.org
C:/dfwforth/examples/shoot-2001-06-05/bench/random/random.frt(17): : 100e_random ( F: -- r )
...
Found 1785 occurrence(s)
-marcel