// How many times does `char` appear in `str`? export function countChar(str: string, char: string): number { return str.split(char).length - 1 } // Generate a 6 character random ID export function randomId(): string { return Math.random().toString(36).slice(7) } // rng(1, 5) #=> result can be 1 2 3 4 or 5 // rng(2) #=> result can be 1 or 2 export function rng(min: number, max = 0) { if (max === 0) { max = min min = 1 } min = Math.ceil(min) max = Math.floor(max) return Math.floor(Math.random() * (max - min + 1)) + min }