mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-14 18:20:52 -05:00
20 lines
351 B
JavaScript
20 lines
351 B
JavaScript
|
// Super quick and dirty LCG PRNG
|
||
|
|
||
|
const m = 0xffffffff
|
||
|
let X = Math.floor(Math.random() * (m - 1))
|
||
|
const a = 16807
|
||
|
const c = 0
|
||
|
|
||
|
// Should probably be a large-ish number
|
||
|
export function seed(i) {
|
||
|
if (i < 0) {
|
||
|
throw new Error('Seed must be a positive integer')
|
||
|
}
|
||
|
X = i & m
|
||
|
}
|
||
|
|
||
|
export function random() {
|
||
|
X = (a * X + c) % m
|
||
|
return X / m
|
||
|
}
|