shared rng function
This commit is contained in:
parent
5fb3b0333d
commit
557e2a8a8d
|
|
@ -6,4 +6,17 @@ export function countChar(str: string, char: string): number {
|
|||
// 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
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user