Re: Shock: rand function is not uniform!
[email protected] (Justin Fletcher) Mon, 18 Feb 2002 21:44:20 GMT
| Newsgroups | perl.riscos |
|---|---|
| Message-ID | <[email protected]> |
In message <[email protected]> James Taylor <[email protected]> wrote: > On Mon 18 Feb, Richard Proctor wrote: > > > > The rand function in the current riscos perl is based on the C > > function "rand", which is well known to be less the ideal. > > Less than ideal? That's rather an understatement. Did you run > the program I attached which plots a graph of its distribution? > >From the graph it is clear that the probability of getting a > value in the middle of rand's range is around about a *quarter* > of the probability of getting values at the two extremes of > its range. Now I don't think you could describe that as > anything less than an unmitigated disaster! Did you run it over an infinite period of time ? The only thing that is clear from empirical evidence is that on that run, things were that way. Whilst it might be less than ideal, a simple incrementing function would satisfy your test, and still be less than ideal. > > if/when we move riscos perl to the more recent version which > > uses the C fucntion rand48 which is more random. > > I really don't think the problem with Perl's rand has anything > to do with any minor randomness failings in C's rand. I have You keep saying 'C's rand'; I don't know what you mean. C's rand is implementation specific, surely. If you mean UnixLib rand, please say that. > written an equivalent test program in C and it is clear from > the graph that whatever failings C's rand might have, it is Again, unclear... I don't know what compiler or library you've linked against and it's impossible to give any comment. > at least approximately uniform. The same goes for C's > _ANSI_rand() function which is supposed to be even less C doesn't have any such function. UnixLib might; be clear. > good. I have also tested Perl's rand function on various > Unix boxes and found that it behaves properly. In comparison, > RISC OS Perl's rand function is *so* broken that I can only > think that there's a bug in the way it was implemented. Sorry if that seems critical, but your comments are unclear. -- Gerph {djf0-.3w6e2w2.226,6q6w2q2,2.3,2m4} URL: http://www.movspclr.co.uk/ .... Eyes to the heavens, screaming at the sky; Trying to send you messages, but choking on goodbye.