ryantenney / random-js Goto Github PK
View Code? Open in Web Editor NEWMersenne Twister (MT19937) implemented in JavaScript as an alternative to Math.random()
Mersenne Twister (MT19937) implemented in JavaScript as an alternative to Math.random()
Original source of MT implementation unknown... Just found it on my drive without attribution. Cleaned it up a little and wrote a wrapper to emulate (and then some) Math.random.
This line implements the multiplication incorrectly:
Line 12 in 6f21a21
JavaScript loses precision with more than 53 bits, so the multiplication must be split into two multiplications, for the upper and lower 16 bits. This is what the other (correct) JavaScript implementations do:
this.mt[this.mti] = (((((s & 0xffff0000) >>> 16) * 1812433253) << 16) + (s & 0x0000ffff) * 1812433253)
+ this.mti;
this.state[this.stateIndex] = (((((s & 0xffff0000) >>> 16) * 1812433253) << 16) + (s & 0x0000ffff) * 1812433253) + this.stateIndex;
this.state[this.stateIndex] >>>= 0;
// avoid multiplication overflow: split 32 bits into 2x 16 bits and process them individually
state[i] = (
(
(
(
( s & 0xffff0000 ) >>> 16
) * 1812433253
) << 16
) + ( s & 0x0000ffff ) * 1812433253
) + i;
this.mt[this.mti] =
(((((s & 0xffff0000) >>> 16) * 1812433253) << 16) + (s & 0x0000ffff) * 1812433253) + this.mti;
this.mt[this.mti] >>>= 0;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.