Which random number generator is used in Scratch 1.4 and where can I find its implementaion in the source code? If it is just libc's random()
, please point me to the spot where it's called.
Asked
Active
Viewed 144 times
2

d33tah
- 10,999
- 13
- 68
- 158
1 Answers
3
Scratch 1.x is written in Squeak Smalltalk. You can get the source code from within Scratch by following these instructions.
The pick random () to ()
block is defined in Scratch-Objects -> ScriptableScratchMorph (instance) -> other ops -> randomFrom:to:
. The basic essential code there is
t5 _ RandomGen next * (t4 - t3) + t3.
Now, what is RandomGen
? It turns out that it's defined in Scratch (in the class initialization) as just being a copy of Squeak's Random
.
According to the Squeak wiki:
The random-number-generator is a Park-Miller generator, it is implemented in the class Random.
Scratch also calls for a random number in some list blocks, where you can do something with "any" list item. This is implemented in list ops -> lineNum:forList:
.

Scimonster
- 32,893
- 9
- 77
- 89