Skip to main content

@std/random@0.1.4
Built and signed on GitHub Actions

UNSTABLE: Various utilities using random number generators. The package also provides seeded pseudo-random number generator.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
94%
Published
4 weeks ago (0.1.4)

Utilities for generating random numbers.

Example of generating a random integer with fixed seed number:

import { randomIntegerBetween } from "@std/random";
import { randomSeeded } from "@std/random";
import { assertEquals } from "@std/assert";

const prng = randomSeeded(1n);

assertEquals(randomIntegerBetween(1, 10, { prng }), 3);

Example of generating a random integer between two values:

import { randomIntegerBetween } from "@std/random";
import { randomSeeded } from "@std/random";

const prng = randomSeeded(BigInt(crypto.getRandomValues(new Uint32Array(1))[0]!));

const randomInteger = randomIntegerBetween(1, 10, { prng });
Built and signed on
GitHub Actions

Add Package

deno add jsr:@std/random

Import symbol

import * as random from "@std/random";
or

Import directly with a jsr specifier

import * as random from "jsr:@std/random";

Add Package

pnpm i jsr:@std/random
or (using pnpm 10.8 or older)
pnpm dlx jsr add @std/random

Import symbol

import * as random from "@std/random";

Add Package

yarn add jsr:@std/random
or (using Yarn 4.8 or older)
yarn dlx jsr add @std/random

Import symbol

import * as random from "@std/random";

Add Package

vlt install jsr:@std/random

Import symbol

import * as random from "@std/random";

Add Package

npx jsr add @std/random

Import symbol

import * as random from "@std/random";

Add Package

bunx jsr add @std/random

Import symbol

import * as random from "@std/random";