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