More on Random

Juan Cires Martinez jcm at mat.upm.es
Thu Jun 3 19:07:33 UTC 1999


I know this might not be common, but I have been running the same image
on a Linux machine for the past couple of weeks (at least, I don't
remember exactly when I started it...) and suddenly Randoms started
generating a first random number outside of the [0,1) range,
specifically, negative values.  Further results from the same Random
seemed OK.  Since the seed initialization uses

	seed := Time millisecondClockValue * self hash.

I checked and found out that they were being initialized to
LargePositiveIntegers, which I'm not sure are correct values.  Anybody
know if this is the problem?  I saved the image and restarted the VM and
now my Randoms are fine.  As a quick hack, the solution I adopted was to
modify Random>>initialize once more to:

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.
	self next                    " forget first result (jcm)"

Greetings, Juan.





More information about the Squeak-dev mailing list