Function: random()
random(args
: { lix
: Pick
<Lix
, "call"
>; }): Promise
<number
>
Returns a random float between 0 (inclusive) and 1 (exclusive).
In deterministic mode, generates reproducible values using xorshift128+ PRNG
(the same algorithm used by V8/Chrome for Math.random()). In normal mode, uses crypto.getRandomValues().
- Normal mode: cryptographic quality via crypto.getRandomValues().
- Deterministic mode: xorshift128+ PRNG (same as V8/Chrome's Math.random()).
- Default seed:
lix_id
unless lix_deterministic_rng_seed
is set.
- State persisted via
lix_deterministic_rng_state
.
- Returns 53-bit precision floats in both modes.
- For ID generation, consider uuidV7 or nanoId instead.
Examples
const lix = await openLix();
const r1 = await random({ lix }) // 0.823...
const r2 = await random({ lix }) // 0.156...
const lix = await openLix({ keyValues: [{ key: "lix_deterministic_mode", value: { enabled: true } }] });
await random({ lix }) // 0.318...
await random({ lix }) // 0.937...
await random({ lix }) // 0.543...
Parameters
Parameter | Type |
---|
args | { lix : Pick <Lix , "call" >; } |
args.lix | Pick <Lix , "call" > |
Returns
Promise
<number
>