Description
Increasing access
xorshift128+ have a better overall randomness and speed as compared to the currently used LCG, although the speed aspect has been mostly observed in RNG implemented in other languages so it is harder to determine how well it will translate to JavaScript. This change can help avoid some of the potential pitfalls with LCG that some users has observed before.
Which types of changes would be made?
- Breaking change (Add-on libraries or sketches will work differently even if their code stays the same.)
- Systemic change (Many features or contributor workflows will be affected.)
- Overdue change (Modifications will be made that have been desirable for a long time.)
- Unsure (The community can help to determine the type of change.)
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- Build process
- Unit testing
- Internationalization
- Friendly errors
- Other (specify if possible)
What's the problem?
There is not a significant problem to solve with this proposal, the main aim is to use the same RNG algorithm as the browser's own Math.random()
implementation.
What's the solution?
Seeded random number generator (RNG) will use xorshift128+. The current algorithm for RNG used in p5.js is an version of a Linear Congruential Generator (LCG).
The main reasoning for this change is for performance. xorshift128+ performs better than LCG and it is the internal implementation of most of the current major browsers for Math.random()
. The random property of xorshift128+ is similar if not better than LCG.
This will be a breaking change as existing seeded RNG will not give the same random number sequence once the algoritm has switched to use xorshift128+. Consideration can be made to create a compatibility addon library that patch seeded RNG to use the old LCG RNG if necessary.
Example implementation of a xorshift128+ backed RNG with compatible API to p5.js can be found here.
Pros (updated based on community comments)
- Potentially better randomness and performance for seeded RNG
Cons (updated based on community comments)
This is a fairly minor change although still in effect a breaking change since it will change the sequence of numbers returned by a seeded random number generator as well as seeded noise. This will only affect seeded RNG, unseeded ones uses Math.random()
which is not seeded.
Proposal status
Under review
Metadata
Metadata
Assignees
Type
Projects
Status