View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Random number generator in SmallTalk - Hubert Liu

At first I had no idea how to use random numbers in SmallTalk, but after some research, there's an easy way to do it.

For your viewing pleasure, here's some VERY helpful code:

|gen max|
gen := FastRandom new.
max := 10.
((gen next*max+1) + 1)floor.


This will generate a random integer between 1 and 10.

If you want to generate a random integer between 5 and 10, you will have to set the max to 5, and shift the number generated by 5. For example...

|gen max|
gen := FastRandom new.
max := 5.
((gen next* max+1) + 5)floor.



Will generate an integer from 5 to 10.

Hope this helps in the future, as it was difficult for our group to find this information.

Links to this Page