In article , Robert A Duff writes: |> snipped-for-privacy@allegro.com (Gavin Scott) writes: |> |> > In comp.arch Robert A Duff wrote: |> > > Ada has some requirements on the built-in (pseudo) random number |> > > generators. See: |> > |> > >
formatting link
|> > |> > > I don't really understand this stuff. Does it result in "terrible", |> > > as you say, output?
I could produce a generator that passed all those, and was close to terrible, but would have to work at it.
|> > Nice short summary of Knuth's tests for randomness in there. |> > |> > But it only requires a period of 2^31-1, |> |> 2**31-2, actually. I'm not sure why it's not 2**31-1.
To allow a 'pure' multiplicative generator with a modulus of 2**31-1.
|> > Looks like a nice formal requirement that the PRNG at least not be |> > abysmally bad :-) |> > |> > But those requirements still don't get you a PRNG that you'd want to |> > use for any serious application I think.
Agreed.
|> > Offhand I don't recall whether the simple linear congruential generators |> > can be constructed to pass Knuth's tests or not (Knuth probably says).
No, not at all. Knuth is, at best, an elementary introduction and contains some blind spots. There are ways of generating excellent linear congruential generators (clue: VERY large moduli).
|> The (pseudo) random number generator included in GNAT (the free Ada |> compiler) has this comment. And we use the same algorithm in our |> compiler (SofCheck, Inc.): |> |> -- Note: the implementation used in this package was contributed by |> -- Robert Eachus. It is based on the work of L. Blum, M. Blum, and |> -- M. Shub, SIAM Journal of Computing, Vol 15. No 2, May 1986. The |> -- particular choices for P and Q chosen here guarantee a period of |> -- 562,085,314,430,582 (about 2**49), and the generated sequence has |> -- excellent randomness properties. For further details, see the |> -- paper "Fast Generation of Trustworthy Random Numbers", by Robert |> -- Eachus, which describes both the algorithm and the efficient |> -- implementation approach used here.
Oh, Lordy! Please, NO! I haven't seen the latter paper, but the former is SERIOUSLY misleading - note that I am not criticising its mathematics, but the way that it presents them for the layman.
Blum, Blum and Shub is an interesting result, but most non-specialists will miss that it is a randomness-expansion method - very unlike more traditional generators. Furthermore, it will expand N bits to N^k for some (unknown) value of k, but not necessarily beyond - I have a test that will cause it to fail at 2^(N/3), with no knowledge of the internals. And, lastly, the proof is asymptotic and therefore may not work for small numbers (which, in pure mathematics terms, may mean any reasonable ones).
|> I haven't read the paper (and probably wouldn't understand it if I did). |> Does this (2**49) seem reasonable? Good? Better than usual? |> It certainly seems to exceed the requirements of the Ada language |> standard.
Bad. Better than the obsolete and trash generators, nowhere near state of the art in 1970. A period of 2^49 means that you should NEVER use more than 2^32 numbers in a complete simulation.
|> In your opinion, should a language standard require a PRNG that *can* be |> used in serious applications, or should it make some minimal |> requirements, and let the serious people roll their own?
Given the extreme specialisation of this area, neither. It should either not include one at all, or two with specifications like:
double random_a (void);
This is intended for use in statistical simulations. Its precise algorithm shall be implementation-defined.
unsigned char *random_b (void);
This is intended for use in cryptography. Its precise algorithm shall be implementation-defined.
Do more than that, and 99.99% of people WILL get it badly wrong.
Regards, Nick Maclaren.