Set::atRandom is extremely nonuniform / suggested fixes
Joshua Scholar
jscholar at access4less.net
Mon Nov 29 16:23:33 UTC 2004
Oops there was a typo in my suggested Set::AtRandom
Here's the one I'm actually using:
atRandom: aGenerator
"Answer a random element of the receiver. Uses aGenerator which
should be kept by the user in a variable and used every time. Use
this instead of #atRandom for better uniformity of random numbers
because only you use the generator. Causes an error if self has no
elements."
| ind entry |
entry _ nil.
[entry == nil] whileTrue: [
self emptyCheck.
ind _ aGenerator nextInt: array size.
entry _ array at: ind.
].
^entry.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20041129/781b8ad3/attachment.htm
More information about the Squeak-dev
mailing list
|