Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alextes/vegas
Vegas helps generate numbers or pick elements based on randomness.
https://github.com/alextes/vegas
deno deno-module denoland random random-generation
Last synced: 2 days ago
JSON representation
Vegas helps generate numbers or pick elements based on randomness.
- Host: GitHub
- URL: https://github.com/alextes/vegas
- Owner: alextes
- Created: 2021-06-09T13:26:37.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-07T14:59:02.000Z (over 3 years ago)
- Last Synced: 2025-01-01T10:17:55.584Z (6 days ago)
- Topics: deno, deno-module, denoland, random, random-generation
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Vegas
Generate random numbers and samples.
Vegas helps do things based on randomness. For example picking a random integer,
picking a random element from a list, or even collecting a unique sample of
elements from a list. This library takes inspiration from
[Python's random library](https://docs.python.org/3/library/random.html).## Usage
```ts
import { randomInt } from "https://deno.land/x/[email protected]/mod.ts";console.log(randomInt(0, 4)); // 2
```## API
Below are examples for all currently available APIs. Except for the
`makeGenerators` and `makeSeededGenerators` functions, all functions draw
randomness from `Math.random`. Use the aforementioned functions to draw
randomness from a different source.```ts
// 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);
```