# uniformInt

> **uniformInt**(`random`, `upperExclusive`): `number`

Defined in: [packages/prng/src/uniform-int.ts:32](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/prng/src/uniform-int.ts#L32)

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

Multiplying a source value by 2^32 produces one unsigned 32-bit draw. When the requested range does not divide 2^32 evenly, a direct remainder would make its lowest outcomes slightly more likely. Rejection sampling discards the incomplete high end of the 32-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

[`RandomSource`](/reference/knotkit/prng/type-aliases/randomsource/)

Function returning values in `[0, 1)`.

### upperExclusive

`number`

Exclusive upper bound, from 1 through 2^32.

## Returns

`number`

## Throws

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