Skip to main content
Deno 2 is finally here 🎉️
Learn more

Vegas

Generate random numbers, samples, and more.

Sometimes you need a random number, index, or even a set of elements from a list. Vegas can help. This library takes inspiration from Python’s random library.

Usage

import { randomInt } from "https://deno.land/x/vegas@1.0.0/mod.ts";

console.log(randomInt(0, 4)); // 2

API

// int from and including two, up to and excluding eight.
randomInt(2, 8);

// int below 4.
randomBelow(4);

// pick a random element from a list.
randomPick([1, 2, 3]);

// pick a sample of two elements from a list.
randomSample([1, 2, 3, 4], 2);

// random float, mostly here for seeded random float generation.
randomFloat();

// initializes all random generators with a seeded random number generator.
const vegas = makeSeededGenerators("my-seed");
vegas.randomInt(2, 32);

// initializes all random generators with a custom random number generator.
const vegasCustom = makeGenerators(Math.random);
vegasCustom.randomInt(0, 10);