overleaf/services/web/scripts/lezer-latex/random.mjs
Mathias Jakobsen 94694a6385 Merge pull request #19057 from overleaf/mj-benchmark-seed-random
[web] Add quick and dirty PRNG for seeding benchmark runs

GitOrigin-RevId: 079f9b565f17b44d7062f6b93c26f694e486c6b9
2024-06-24 12:04:46 +00:00

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
}