excalidraw/src/random.ts
dependabot[bot] f1fc308a5d
chore(deps): bump nanoid from 2.1.11 to 3.1.20 (#2581)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Panayiotis Lipiridis <lipiridis@gmail.com>
2021-01-11 12:47:10 +02:00

16 lines
399 B
TypeScript

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);
export const reseed = (seed: number) => {
random = new Random(seed);
testIdBase = 0;
};
export const randomId = () =>
process.env.NODE_ENV === "test" ? `id${testIdBase++}` : nanoid();