# uniformInt64

> **uniformInt64**(`random`, `upperExclusive`): `bigint`

Defined in: [packages/prng/src/uniform-int64.ts:35](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/prng/src/uniform-int64.ts#L35)

Draw an integer uniformly from `0..upperExclusive - 1`.

This is the 64-bit counterpart of `uniformInt`. It consumes a source that already returns unsigned 64-bit draws, so no floating-point step stands between the generator and the sample, and bounds above 2^32 stay exact.

When the requested range does not divide 2^64 evenly, a direct remainder would make its lowest outcomes slightly more likely. Rejection sampling discards the incomplete high end of the 64-bit range before taking the remainder, so every returned integer has exactly the same number of source draws mapping to it.

The source can be seeded or otherwise injected by the caller. Each value is validated at the point it is consumed because a stateful source can become invalid after earlier valid draws.

Consumes one source draw in the common case. The rejection region is always smaller than `upperExclusive`, so fewer than half of all draws are rejected and the expected number of draws is below two.

## Parameters

### random

[`RandomSource64`](/reference/knotkit/prng/type-aliases/randomsource64/)

Function returning unsigned 64-bit values in `[0, 2^64)`.

### upperExclusive

`bigint`

Exclusive upper bound, from 1 through 2^64.

## Returns

`bigint`

## Throws

With code `INVALID_BOUND` when the bound is not a bigint in `1..2^64`, or `INVALID_SOURCE_VALUE` when the source returns a value outside `[0, 2^64)`.
