@drop-in/new
Version:
A SvelteKit Svelte 5 PocketBase Starter Kit with a CLI
26 lines (22 loc) • 692 B
text/typescript
export function getNonCryptoRandomValues(array: Uint8Array) {
if (array === null) {
throw new TypeError('array cannot be null');
}
// Fill the array with random values
for (let i = 0; i < array.length; i++) {
array[i] = Math.floor(Math.random() * 256); // Random byte (0-255)
}
return array;
}
export function randomCharacters(length: number) {
let result = '';
const characters =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
let counter = 0;
while (counter < length) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
counter += 1;
}
return result;
}