[Newbies] Re: What's wrong with this statement?

Cerebus 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]

gives:

CFE72E55A8C35387C9932D3235937FE6
A1760C4F27B161A4D2431C94751A2E65
D9EC4066D2DBD7A00B17B6FC16D985DC
D3140D928C14D8EA7AEB0CC814A2CA8C
EFB37CECB90EFDCF2F93BC34245118C
1B215016A0812E04A5600FA88373BD7B
7B52EB7F11C0DC822B272B70DCE61890
1D165F2BAF12E8596D496745A41A4BF4
E8C62D390B69B26CD9FEAF58BD68C17
3FBEA83CCB11EEDF6993E9BB60171F35

-- Tim

On Sat, Aug 2, 2008 at 11:00 AM, Cerebus <cerebus2 at gmail.com> wrote:
> Bug submitted.
>
> http://bugs.squeak.org/view.php?id=7142
>
> I may even attempt a fix.  :)
>
> -- Tim
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Integer-atRandom.st
Type: application/octet-stream
Size: 838 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/beginners/attachments/20080803/17fa7ee2/Integer-atRandom.obj


More information about the Beginners mailing list