-
Notifications
You must be signed in to change notification settings - Fork 64
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
Added a random number primitive #645
base: pharo-12
Are you sure you want to change the base?
Added a random number primitive #645
Conversation
Why do we need an arbitrary pseudo random generator in the VM? |
The goal was to have a fast way to generate pseudo-random number while we were replacing the default Pharo generator, which is quite bad |
Hi @BastouP411 I imagine this PR is now obsolete, replaced by a full Pharo version of the code. I'll close this PR, please feel free to reopen it if I was mistaken |
Okay I did not see this was closed. r := Random new.
r seed: 42.
[ r privateNextValue ] bench.
"With primitive: 450,129,783 iterations in 5 seconds 2 milliseconds. 89989960.616 per second"
"Without primitive: 7,317,172 iterations in 5 seconds 3 milliseconds. 1462556.866 per second"
89989960.616/1462556.866. "Primitive version is 61.5 times faster !" The version that uses the primitive is 61.5 times faster so there is a benefit when generating lots of random numbers. |
I profiled the code a bit in latest Pharo12. The Pharo code is generating lots of large integers. It would be interesting to see how to reimplement it without |
The biggest problems I see are
|
How could we reimplement without these large integers ? cutting the multiplication and using multiple bitAnd ? |
That would be fun to try. Check the implementation of |
For an initial implementation of 64-bit register implementation you may check this PR pharo-project/pharo#14616 |
Added
primitiveRandom
which generates a random 31 bits integer basing on a 64 bits state.Based on Permuted Congruential Generators (https://www.pcg-random.org/index.html)