atRandom...
Peter Smet
peter.smet at flinders.edu.au
Wed Oct 7 05:53:14 UTC 1998
I love the way Squeak uses the random number generator in the collection
class.
This hugely simplifies a lot of things. I have run into some portability
issues with
this, however. Squeak uses truncation for 'asInteger', Dolphin uses
rounding.
This can make a big difference. Does anyone know what the ANSI standard
for 'asInteger' should be? Regardless of this, I think it may be less
ambiguous
to use 'truncated' rather than asInteger.
index := (aGenerator next * self size) asInteger + 1.
index := (aGenerator next * self size) truncated + 1.
The other thing I noticed is that atRandom and atRandom: aRNG duplicate
a lot of code. Why not implement atRandom as this:
atRandom
^self atRandom: RandomForPicking
Peter....
More information about the Squeak-dev
mailing list
|