excalidraw/src/random.ts

16 lines
416 B
TypeScript
Raw Normal View History

2020-03-23 16:38:41 -07:00
import { Random } from "roughjs/bin/math";
import { nanoid } from "nanoid";
import { isTestEnv } from "./utils";
2020-03-23 16:38:41 -07:00
let random = new Random(Date.now());
let testIdBase = 0;
export const randomInteger = () => Math.floor(random.next() * 2 ** 31);
2020-03-23 16:38:41 -07:00
export const reseed = (seed: number) => {
2020-03-23 16:38:41 -07:00
random = new Random(seed);
testIdBase = 0;
};
2020-03-23 16:38:41 -07:00
export const randomId = () => (isTestEnv() ? `id${testIdBase++}` : nanoid());