'From Squeak3.10.2 of ''5 June 2008'' [latest update: #7179] on 2 August 2008 at 4:52:09 pm'!
"Change Set: testAtRandomOddity-wiz
Date: 2 August 2008
Author: (wiz) Jerome Peace
wiz 8/2/2008 16:47
A test for atRandom exausting the the bits in its random generator.
When asking for LargeInteger instance atRandom the number could have more bits than a single random number. The bug shows up as the lower order bits all being zero and the last bit being one because of the increment after truncation.
This is a test to help Mantis 7142"!
!RandomTest methodsFor: 'tests' stamp: 'wiz 8/2/2008 16:43'!
testRandomOddity
"Test atRandom (actually #atRandom: to see if large integers can be chosen
completely fairly.
Without special effort random runs out of bits to choose amoung more that 2^50 choices.
This tests the low order bit to see if it gets stuck for all samples.
This will catch the problem cases. It will also give false positives sometimes.
False positives will show up by chance
once every ( cases size * 2 ) out of ( 2 ^ enough ) cases. "
| enough cases samples rejects |
enough := 10 . "number of samples"
cases :=
(30 to: 80) collect: [ :each | 2 raisedTo: each ] .
samples :=
cases collect: [ :each |
{ each .
( ( 1 to: enough ) collect: [ :eachOne |
each atRandom ] ) } ] .
rejects :=
samples select: [ :each |
( each second noneSatisfy: [ :eachOne |
eachOne even ] )
or: [ each second
allSatisfy: [ :eachOne |
eachOne even ] ] ] .
self assert: rejects isEmpty .
! !