Better solution to Random>>initializa

Juan Cires Martinez jcm at mat.upm.es
Thu May 27 14:09:17 UTC 1999


The problem with the initialization of a Random is in the statement:

	seed := Time millisecondClockValue * self hash.

which has a problem when self hash evaluates to zero.  The solution I
propose is to modify that line:

    initialize
	" Set a reasonable Park-Miller starting seed "
	seed := Time millisecondClockValue * (self hash + 1).

	a := 16r000041A7 asFloat.    " magic constant =      16807 "
	m := 16r7FFFFFFF asFloat.    " magic constant = 2147483647 "
	q := (m quo: a) asFloat.
	r  := (m \\ a) asFloat.

Greetings, Juan.

PS: I have translated to Squeak the C code to generate random numbers
with a normal distribution published in "Numerical Recipes in C", second
edition, and implemented the class NormalRandom.  Is it legal to publish 
such code?





More information about the Squeak-dev mailing list