[Cryptography Team] Cryptography: Fortuna>>nextInt:
C. David Shaffer
cdshaffer at acm.org
Mon Jul 5 19:58:20 UTC 2010
I missed a method in my merge of Chris' branch:
Fortuna>>nextInt: was removed by cmm.7 with the comment:
"Removed faulty optimization of Fortuna>>#nextInt:. Now inherits slower
but correct one from superclass."
Chris: It looks like the original version has persistent (with
underscores fixed) in the latest version. Can you confirm that I should
remove the version below?
Feedback from others?
"Answer a random integer in the interval [1, anInteger]."
| r high bits highestMultiple |
anInteger strictlyPositive ifFalse: [ self error: 'Range must be positive' ].
high := anInteger-1.
bits := high highBit.
"Calculate highestMultiple of anInteger, so that we can simply divide r by anInteger and use the remainder for the random value."
highestMultiple := (1 bitShift: bits) truncateTo: anInteger.
[ (r := self nextBits: bits)
and: highestMultiple ] whileFalse.
More information about the Cryptography