Skip to content

Random

Random generation and async utility functions.

No permission required.

Methods

id(length?)

Generate a short unique ID.

typescript
const id = Random.id();     // e.g. "a3f8k2"
const long = Random.id(12); // e.g. "a3f8k2m9p1x7"

uuid()

Generate a UUID v4.

typescript
const uuid = Random.uuid(); // e.g. "550e8400-e29b-41d4-a716-446655440000"

number(min?, max?)

Generate a random integer.

typescript
const n = Random.number(1, 100); // 1-100 inclusive

password()

Generate a random password.

typescript
const pw = Random.password(); // e.g. "xK9#mP2$nL"

username()

Generate a random username.

typescript
const user = Random.username(); // e.g. "shadow_hacker42"

pick(array)

Pick a random element from an array.

typescript
const color = Random.pick(["red", "green", "blue"]);

pickMultiple(array, count)

Pick multiple unique random elements.

typescript
const team = Random.pickMultiple(["Alice", "Bob", "Charlie", "Dave"], 2);
// e.g. ["Charlie", "Alice"]

sleep(ms)

Wait for a duration. Returns a Promise.

typescript
await Random.sleep(2000); // wait 2 seconds

HotBunny Interactive Entertainment Inc.