2020-03-23 16:38:41 -07:00
|
|
|
import { Random } from "roughjs/bin/math";
|
2021-01-11 12:47:10 +02:00
|
|
|
import { nanoid } from "nanoid";
|
2020-03-23 16:38:41 -07:00
|
|
|
|
|
|
|
let random = new Random(Date.now());
|
|
|
|
let testIdBase = 0;
|
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
export const randomInteger = () => Math.floor(random.next() * 2 ** 31);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
export const reseed = (seed: number) => {
|
2020-03-23 16:38:41 -07:00
|
|
|
random = new Random(seed);
|
|
|
|
testIdBase = 0;
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
export const randomId = () =>
|
|
|
|
process.env.NODE_ENV === "test" ? `id${testIdBase++}` : nanoid();
|