16 lines
416 B
TypeScript
16 lines
416 B
TypeScript
5 years ago
|
import { Random } from "roughjs/bin/math";
|
||
4 years ago
|
import { nanoid } from "nanoid";
|
||
3 years ago
|
import { isTestEnv } from "./utils";
|
||
5 years ago
|
|
||
|
let random = new Random(Date.now());
|
||
|
let testIdBase = 0;
|
||
|
|
||
5 years ago
|
export const randomInteger = () => Math.floor(random.next() * 2 ** 31);
|
||
5 years ago
|
|
||
5 years ago
|
export const reseed = (seed: number) => {
|
||
5 years ago
|
random = new Random(seed);
|
||
|
testIdBase = 0;
|
||
5 years ago
|
};
|
||
5 years ago
|
|
||
3 years ago
|
export const randomId = () => (isTestEnv() ? `id${testIdBase++}` : nanoid());
|