Somebody check me out here, 'cause I think I'm close but something doesn't seem quite right.
Attached is a new Integer>atRandom I'm playing with. I break the integer into a ByteArray and call #atRandom for every byte, using 255 as the bounding value for all but the first byte. The bounding value for the first byte is itself minus 1. Concatenated together we get a byte array representing a random value less than the bounding value.
I think. Maybe I'm doing this wrong. I feel like the first byte treatment is wrong but I don't know how to achieve the same result--without it the random value often exceeds the bounding value.
I went this route as it avoids doing a bunch of bit shifts I'd probably get wrong anyway.
10 timesRepeat: [Transcript show: ((2 raisedTo: 128) atRandom hex); cr]
gives:
CFE72E55A8C35387C9932D3235937FE6 A1760C4F27B161A4D2431C94751A2E65 D9EC4066D2DBD7A00B17B6FC16D985DC D3140D928C14D8EA7AEB0CC814A2CA8C EFB37CECB90EFDCF2F93BC34245118C 1B215016A0812E04A5600FA88373BD7B 7B52EB7F11C0DC822B272B70DCE61890 1D165F2BAF12E8596D496745A41A4BF4 E8C62D390B69B26CD9FEAF58BD68C17 3FBEA83CCB11EEDF6993E9BB60171F35
-- Tim
On Sat, Aug 2, 2008 at 11:00 AM, Cerebus cerebus2@gmail.com wrote:
Bug submitted.
http://bugs.squeak.org/view.php?id=7142
I may even attempt a fix. :)
-- Tim
"Cerebus" == Cerebus cerebus2@gmail.com writes:
Cerebus> Attached is a new Integer>atRandom I'm playing with. I break the Cerebus> integer into a ByteArray and call #atRandom for every byte, using 255 Cerebus> as the bounding value for all but the first byte. The bounding value Cerebus> for the first byte is itself minus 1. Concatenated together we get a Cerebus> byte array representing a random value less than the bounding value.
You're going to get a correlation at some point. You're merely spreading the same amount of entropy around in different places. It's not "more random".
Look at it this way. The cycle will repeat in 2**53 calls to the random number generator. By calling it 10 times for each "result", you're using causing it to loop 10 times as fast. You can't get 10 pounds of entropy out of a 5 pound sack.
beginners@lists.squeakfoundation.org