1
0
mirror of https://github.com/excalidraw/excalidraw.git synced 2024-11-10 11:35:52 +01:00
excalidraw/src/random.ts

16 lines
416 B
TypeScript
Raw Normal View History

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