aboutsummaryrefslogtreecommitdiff
path: root/src/lib/generate.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/generate.ts')
-rw-r--r--src/lib/generate.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/generate.ts b/src/lib/generate.ts
new file mode 100644
index 0000000..8e25aa0
--- /dev/null
+++ b/src/lib/generate.ts
@@ -0,0 +1,20 @@
+import prand from 'pure-rand';
+
+const seed = Date.now() ^ (Math.random() * 0x100000000);
+const rng = prand.xoroshiro128plus(seed);
+
+export function random(min: number, max: number) {
+ return prand.unsafeUniformIntDistribution(min, max, rng);
+}
+
+export function getRandomChars(
+ n: number,
+ chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
+) {
+ const arr = chars.split('');
+ let s = '';
+ for (let i = 0; i < n; i++) {
+ s += arr[random(0, arr.length - 1)];
+ }
+ return s;
+}