[Newbies] Re: What's wrong with this statement?
cerebus2 at gmail.com
Mon Aug 4 02:52:09 UTC 2008
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]
On Sat, Aug 2, 2008 at 11:00 AM, Cerebus <cerebus2 at gmail.com> wrote:
> Bug submitted.
> I may even attempt a fix. :)
> -- Tim
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 838 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/beginners/attachments/20080803/17fa7ee2/Integer-atRandom.obj
More information about the Beginners