# Module /rng

Pseudo-random number generation for bounded integers, floats, booleans, and collection sampling.

```tangu
(use /rng)
```

## Functions & symbols

### choose

`(rng/choose coll) -> Any`

Uniformly selects a single element from a collection, or returns `()` if empty.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `coll` | `Any` | no | Sequence, Range, Slab, String, Set, or Map |

```tangu
(rng/choose [:a :b :c])
(rng/choose 1..=6)
```

### random-bool

`(rng/random-bool) -> Bool`

Generates a random Bool with fair 50/50 odds or Bernoulli probability `p` in `0.0..=1.0`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `p` | `Float` | no | Optional Bernoulli probability in `0.0..=1.0` (defaults to `0.5`) |

```tangu
(rng/random-bool)
(rng/random-bool 0.25)
```

### random-float

`(rng/random-float) -> Float`

Generates a uniform random Float in `[0.0, 1.0)`, `[0.0, end)`, `[start, end)`, or a Range.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `end-or-range` | `Any` | no | Optional upper bound `end > 0.0` or float `Range` (e.g. `-1.0..1.0`) |
| `end` | `Float` | no | Optional exclusive upper bound when `start` is provided |

```tangu
(rng/random-float)
(rng/random-float 10.0)
(rng/random-float -1.0..1.0)
```

### random-int

`(rng/random-int end) -> Int`

Generates a uniform random Int in `[0, end)`, `[start, end)`, or from an integer Range.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `end-or-range` | `Any` | no | Exclusive upper bound `end > 0` or integer `Range` (e.g. `1..=6`, `0..=100|5`) |
| `end` | `Int` | no | Optional exclusive upper bound when `start` is provided |

```tangu
(rng/random-int 100)
(rng/random-int 10 20)
(rng/random-int 1..=6)
```

### sample

`(rng/sample coll k) -> Any`

Samples `k` distinct elements without replacement in random order, clamping `k`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `coll` | `Any` | no | Sequence, Range, Slab, String, Set, or Map |
| `k` | `Int` | no | Number of distinct elements to sample (clamped to `0..(count-of coll)`) |

```tangu
(rng/sample [1 2 3 4 5] 3)
(rng/sample 1..=52 5)
```

### shuffle

`(rng/shuffle coll) -> Any`

Returns a new collection with its elements shuffled in uniformly random order.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `coll` | `Any` | no | Sequence, Range, Slab, String, Set, or Map |

```tangu
(rng/shuffle [1 2 3 4 5])
```

### shuffle<-

`(rng/shuffle<- #mut coll) -> Any`

Shuffles a mutable collection in place using Fisher-Yates and returns the mutated collection.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `coll` | `#mut Any` | no | Mutable Array, Int-Array, Float-Array, Dec-Array, Slab, or Map |

```tangu
(let #mut deck [1 2 3 4]) (rng/shuffle<- deck)
```
