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?
Thanks!
David
Fortuna>>nextInt: anInteger "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) between: 0 and: highestMultiple ] whileFalse. ^ r\anInteger+1
Hi David, yes, absolutely, Fortuna>>#nextInt: should be deleted, because it is a flawed implementation, as the following script demonstrates:
"explore it" |f| f:=Fortuna picker. ((1 to: 1000) collect: [ : n | f nextInt: 6 ]) asBag sortedCounts
Note the consistent, heavy weighting for "1"..
The method should be deleted so it can inherit the generic one in the superclass.
Thanks and Regards, Chris
On Mon, Jul 5, 2010 at 2:58 PM, C. David Shaffer cdshaffer@acm.org wrote:
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?
Thanks!
David
Fortuna>>nextInt: anInteger "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) between: 0 and: highestMultiple ] whileFalse. ^ r\anInteger+1
On 07/06/10 11:52, Chris Muller wrote:
Hi David, yes, absolutely, Fortuna>>#nextInt: should be deleted, because it is a flawed implementation, as the following script demonstrates:
"explore it" |f| f:=Fortuna picker. ((1 to: 1000) collect: [ : n | f nextInt: 6 ]) asBag sortedCounts
Note the consistent, heavy weighting for "1"..
Ouch, I see. Done.
David
cryptography@lists.squeakfoundation.org