Add ?seed= support
This commit is contained in:
21
src/util.ts
21
src/util.ts
@@ -2,6 +2,23 @@ import dictionary from "./dictionary.json";
|
||||
|
||||
export const dictionarySet: Set<string> = new Set(dictionary);
|
||||
|
||||
export function pick<T>(array: Array<T>): T {
|
||||
return array[Math.floor(array.length * Math.random())];
|
||||
function mulberry32(a: number) {
|
||||
return function () {
|
||||
var t = (a += 0x6d2b79f5);
|
||||
t = Math.imul(t ^ (t >>> 15), t | 1);
|
||||
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
}
|
||||
|
||||
const seed = Number(new URLSearchParams(window.location.search).get("seed"));
|
||||
const makeRandom = () => (seed ? mulberry32(seed) : () => Math.random());
|
||||
let random = makeRandom();
|
||||
|
||||
export function resetRng(): void {
|
||||
random = makeRandom();
|
||||
}
|
||||
|
||||
export function pick<T>(array: Array<T>): T {
|
||||
return array[Math.floor(array.length * random())];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user