mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
94694a6385
[web] Add quick and dirty PRNG for seeding benchmark runs GitOrigin-RevId: 079f9b565f17b44d7062f6b93c26f694e486c6b9
19 lines
351 B
JavaScript
19 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
|
|
}
|