Re: Shock: rand function is not uniform!
On Tue 19 Feb, Justin Fletcher wrote: James Taylor wrote: Please look at the problem before passing comment. Still, it's empirical evidence; whilst it may be skewed there's very little you can say from empirical evidence other than that over the period... I said this. I think your condescension is rather unnecessary. You *still* haven't run the program have you? Please run it, understand it, and only then make such comments, otherwise you run the risk of seeming foolish. I'm referring to Acorn C Perl isn't built with Acorn C, though; I now know that UnixLib was used to the *exclusion* of the standard Acorn CLib. Previously I thought UnixLib would only be used for the things not provided by CLib which is why I thought it strange that rand() shouldn't work. I stand corrected, thank you. if you want to comment on the randomness of perl; you will have to use UnixLib. As a user of Perl I can comment on the randomness of Perl regardless of whether I also happen to be a user of UnixLib. In fact, I've never used UnixLib and I'm not familiar with its workings. If I were, I'd just replace its rand function with a C equivalent of the Mitchell-Moore generator I posted here recently. -- James Taylor [EMAIL PROTECTED] Based in Southam, Cheltenham, UK. PGP key available ID: 3FBE1BF9 Fingerprint: F19D803624ED6FE8 370045159F66FD02
Re: Shock: rand function is not uniform!
In message [EMAIL PROTECTED] James Taylor [EMAIL PROTECTED] wrote: On Tue 19 Feb, Justin Fletcher wrote: James Taylor wrote: Please look at the problem before passing comment. Still, it's empirical evidence; whilst it may be skewed there's very little you can say from empirical evidence other than that over the period... I said this. I think your condescension is rather unnecessary. I think your belief that empirical evidence is proof is wrong; which is what I'm stating. You *still* haven't run the program have you? Please run it, understand it, and only then make such comments, otherwise you run the risk of seeming foolish. It didn't work. It's like saying that I've observed only 20 white men in the street, therefore I assume that the world is made up of white men. Empirical evidence, is still only empirical evidence. I've not denied that your results appear correct, just that I can't say that they are awful or anything else about them except that they appear to be less than ideal. You began by talking about perl rand function then went off to talk about C rand functions and their implication, which as I stated made little sense, so I can only assume that you where unsure what you meant on other fronts. I'm sure you have a much more solid foundation in statistical methods than I, but any results that you gain from a random number function may only indicate possible areas of concern. Your statements were making it out as if the results were the only factors - they're not; they are indicative of an underlying issue which has now been addressed. I'm referring to Acorn C Perl isn't built with Acorn C, though; I now know that UnixLib was used to the *exclusion* of the standard Acorn CLib. Previously I thought UnixLib would only be used for the things not provided by CLib which is why I thought it strange that rand() shouldn't work. I stand corrected, thank you. Ah; right. if you want to comment on the randomness of perl; you will have to use UnixLib. As a user of Perl I can comment on the randomness of Perl regardless of whether I also happen to be a user of UnixLib. I agree; it was just at odds with the other comments you made. -- 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.
Re: Shock: rand function is not uniform!
On Mon, Feb 18, 2002 at 07:27:03AM +, Richard Proctor wrote: On Mon 18 Feb, James Taylor wrote: On Fri 15 Feb, James Taylor wrote: The rand() function as implemented in RISC OS Perl 1.13 for the RiscPC is *not* uniform as it should be. Err... It's been awfully quiet since I posted that. Been busy Been in Germany for the Fourth German Perl Workshop. Is there anybody there? Yes As for previous answer, plus there was no public e-mail access there. Does anybody care? Yes. The rand function in the current riscos perl is based on the C functionrand, which is well known to be less the ideal. if/when we move riscos perl to the more recent version which uses the C fucntion rand48 which is more random. As Richard says, assuming that one has an implementation of rand48 for RISC OS. I've not looked into random number stuff ever, but my understanding of the C rand() function is what Richard says. My general understanding about random numbers on computers is that the question to ask is 'well, how random do you want it?' in that it's very hard for an essentially non-random machine to fake random numbers for you; that there are different tests for randomness, different ways of generating pseudo random numbers that pass different combinations of the randomness tests, and that no method is perfect. Nicholas Clark -- EMCFT http://www.ccl4.org/~nick/CV.html
Re: Shock: rand function is not uniform!
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! 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 written an equivalent test program in C and it is clear from the graph that whatever failings C's rand might have, it is at least approximately uniform. The same goes for C's _ANSI_rand() function which is supposed to be even less 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. [Re: alternative random function] Go ahead post it. Okay, thanks, here you go: { my @q; # Holds random number queue # init_random() parameters: # Either a number to use as a seed # or none to seed on PID and time sub init_random (;$) { my $seed = shift; if (defined $seed) { srand $seed; } else { srand(($$ + ($$ 15)) ^ time); } @q = (); push @q, int rand(1 31) while @q 55; } # random() parameters: # Either a multiplier $mul for an int between 0=x$mul # or none for a float between 0=x1, # See Knuth vol 2 sec 3.2.2 eq 7 for the algorithm used sub random (;$) { my $mul = shift; init_random unless @q; my $next = ($q[-24] + $q[-55]) % (1 31); push @q, $next; shift @q; if (defined $mul) { return int $next / (1 31) * $mul; } else { return $next / (1 31); } } } Hope that's helpful to someone... :-) -- James Taylor [EMAIL PROTECTED] Based in Southam, Cheltenham, UK. PGP key available ID: 3FBE1BF9 Fingerprint: F19D803624ED6FE8 370045159F66FD02
Re: Shock: rand function is not uniform!
On Mon 18 Feb, James Taylor wrote: On Fri 15 Feb, James Taylor wrote: The rand() function as implemented in RISC OS Perl 1.13 for the RiscPC is *not* uniform as it should be. Err... It's been awfully quiet since I posted that. Been busy Is there anybody there? Yes Does anybody care? Yes. The rand function in the current riscos perl is based on the C functionrand, which is well known to be less the ideal. if/when we move riscos perl to the more recent version which uses the C fucntion rand48 which is more random. ...my own random number generator in Perl... If anyone's interested, I can post it. I take it the answer is no then? :-( Go ahead post it. Richard -- Personal Work - Waveney Consulting Mail: [EMAIL PROTECTED] [EMAIL PROTECTED] Web: http://www.waveney.org http://www.WaveneyConsulting.com Independent Telecommunications Consultant, ATM expert, Web Analyst