-
-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integer >> #atRandom seems deterministic #13003
Comments
I am not sure this is really a bug, it depends how you look at it. Anyway, you already give a solution. Another solution would be to access the shared random generator that is being used:
You can send it initialize, useClockBasedSeed, useUnixRandomGeneratorSeed or just set a new seed of your own. |
I second what @svenvc said. Randomness cannot "just" be generated. An image is a stable artefact and so reopening gives the same result unless you give the initialize randomness to it. This can be from the OS are manually but hard to do automatic because the output would be detereministic again. This is usually called seeding. I tend to use
and keep the random object which seeds the Random in a way you can expect different values. Creating Random is slow so keeping one object is preferrable |
I would assume that a method named |
Maybe we could do the same as with UUIGenerator, namely add a class side startUp message to initialize and register with SessionManager in initializedSessionManager. That way a newly seeded SharedRandom globalGenerator will be available when the image comes up. This might be closer to user expectations. |
Yes, we need to startup the random generator everytime. |
I would change the class side of SharedRandom to:
By using startUp without the resuming parameter, the reset happens both when the image comes up and when the image is saved. BTW, the default seeding of Random is clock based. I am not sure if initializedSessionManager has to be changed or not, it seems unused. |
PR: #13022 |
The PR has been integrated |
Bug description
Starting from a new image, the first executions of
10 atRandom
are always returning 6, 3, 6, 2 ... in Pharo 9 and 7, 4, 6, 5, 4 ... in Pharo 11.Results seem to be following a deterministic function.
To Reproduce
10 atRandom
and print first results, ex:1 to: 10 do: [ :i | 10 atRandom crTrace ]
Expected behavior
As its name states, this function should provide users with non-deterministic results.
Context
For an experiment, I am executing a program that initialize the image with random parameters.
Initialized images must be different from each others.
As a workaround I now use
Random new next
instead ofatRandom
.Version information:
The text was updated successfully, but these errors were encountered: