excalidraw/src/random.ts

16 lines
395 B
TypeScript
Raw Normal View History

2020-03-23 16:38:41 -07:00
import { Random } from "roughjs/bin/math";
import nanoid from "nanoid";
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 = () =>
process.env.NODE_ENV === "test" ? `id${testIdBase++}` : nanoid();