newLISP Fan Club

Forum => Whither newLISP? => Topic started by: Kazimir Majorinc on June 29, 2010, 12:56:27 PM

Title: Randoms and the edges of the segment
Post by: Kazimir Majorinc on June 29, 2010, 12:56:27 PM
I noticed following behaviour of the random primitive.


> (dotimes(i 200000)(let((r (random)))(unless (and (< 0 r) (< r 1))(println "edge " (inc counter) ". " r))))
edge 1. 1
edge 2. 1
edge 3. 0
edge 4. 1
edge 5. 1
edge 6. 1
edge 7. 0
edge 8. 1
edge 9. 0
edge 10. 1
edge 11. 0
true


The first surprise is that edge cases happen - but OK, it is matter of design; I don't know is it mentioned in manual. Other surprise is that edge cases happen roughly once in 16384 times and that might be too frequent - if random returns some ten significant digits.
Title: Re: Randoms and the edges of the segment
Post by: Lutz on June 29, 2010, 02:43:10 PM
This only happens on Windows where the raw internal random generator only returns integer values between 0 and 32767 (15 bits).  On most Unixes you will (almost) never see it, where the internal random generators return 31 significant bits.