🎲 Generates a cryptographically strong random float within a range.

Uses the standard Web Crypto API (globalThis.crypto).

Syntax

TypeScript
import { randomFloat } from '@opentf/std';

randomFloat(min: number, max: number): number;

Parameters

NameTypeDescription
minnumberThe minimum value (inclusive).
maxnumberThe maximum value (exclusive).

Returns

A random float between min (inclusive) and max (exclusive).

Examples

TypeScript
randomFloat(0, 1) //=> 0.7234891234567891
randomFloat(1, 5) //=> 3.456789123456789
Last updated on
Edit this page