# Random

<a id="random"></a>

# Random

```cpp
#include <icy/random.h>

class Random
```

[Defined in src/base/include/icy/random.h:25](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L25)

[Random](#random) implements a pseudo random number generator (PRNG) using the Mersenne Twister algorithm (std::mt19937).

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Random`](#random-1)  | Creates and initializes the PRNG. The stateSize parameter is accepted for API compatibility but is ignored; the engine always uses mt19937's fixed state size. |
|  | [`~Random`](#random-2)  | Destroys the PRNG. |
| `void` | [`seed`](#seed)  | Seeds the pseudo random generator with the given seed. |
| `void` | [`seed`](#seed-1)  | Seeds the pseudo random generator with entropy from std::random_device. |
| `uint32_t` | [`next`](#next)  | Returns the next pseudo random number from the mt19937 engine. |
| `uint32_t` | [`next`](#next-1)  | Returns the next pseudo random number in the range [0, n). |
| `char` | [`nextChar`](#nextchar)  | Returns the next pseudo random byte as a char. |
| `bool` | [`nextBool`](#nextbool)  | Returns the next pseudo random boolean value. |
| `float` | [`nextFloat`](#nextfloat)  | Returns the next pseudo random float in [0.0, 1.0]. |
| `double` | [`nextDouble`](#nextdouble)  | Returns the next pseudo random double in [0.0, 1.0]. |

---

<a id="random-1"></a>

### Random

```cpp
Random(int stateSize = 256)
```

[Defined in src/base/include/icy/random.h:32](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L32)

Creates and initializes the PRNG. The stateSize parameter is accepted for API compatibility but is ignored; the engine always uses mt19937's fixed state size.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `stateSize` | `int` | Ignored; present for API compatibility only. |

---

<a id="random-2"></a>

### ~Random

```cpp
~Random()
```

[Defined in src/base/include/icy/random.h:35](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L35)

Destroys the PRNG.

---

<a id="seed"></a>

### seed

```cpp
void seed(uint32_t seed)
```

[Defined in src/base/include/icy/random.h:39](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L39)

Seeds the pseudo random generator with the given seed.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `seed` | `uint32_t` | 32-bit seed value. |

---

<a id="seed-1"></a>

### seed

```cpp
void seed()
```

[Defined in src/base/include/icy/random.h:42](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L42)

Seeds the pseudo random generator with entropy from std::random_device.

---

<a id="next"></a>

### next

```cpp
uint32_t next()
```

[Defined in src/base/include/icy/random.h:46](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L46)

Returns the next pseudo random number from the mt19937 engine. 
#### Returns
Pseudo random uint32_t value.

---

<a id="next-1"></a>

### next

```cpp
uint32_t next(uint32_t n)
```

[Defined in src/base/include/icy/random.h:51](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L51)

Returns the next pseudo random number in the range [0, n). 
#### Returns
Pseudo random value in [0, n).

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `n` | `uint32_t` | Upper bound (exclusive). |

---

<a id="nextchar"></a>

### nextChar

```cpp
char nextChar()
```

[Defined in src/base/include/icy/random.h:55](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L55)

Returns the next pseudo random byte as a char. 
#### Returns
Pseudo random char value.

---

<a id="nextbool"></a>

### nextBool

```cpp
bool nextBool()
```

[Defined in src/base/include/icy/random.h:59](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L59)

Returns the next pseudo random boolean value. 
#### Returns
true or false with equal probability.

---

<a id="nextfloat"></a>

### nextFloat

```cpp
float nextFloat()
```

[Defined in src/base/include/icy/random.h:63](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L63)

Returns the next pseudo random float in [0.0, 1.0]. 
#### Returns
Pseudo random float value.

---

<a id="nextdouble"></a>

### nextDouble

```cpp
double nextDouble()
```

[Defined in src/base/include/icy/random.h:67](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L67)

Returns the next pseudo random double in [0.0, 1.0]. 
#### Returns
Pseudo random double value.

## Public Static Methods

| Return | Name | Description |
|--------|------|-------------|
| `void` | [`getSeed`](#getseed) `static` | Fills the buffer with entropy bytes from std::random_device. |

---

<a id="getseed"></a>

### getSeed

`static`

```cpp
static void getSeed(char * seed, unsigned length)
```

[Defined in src/base/include/icy/random.h:72](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L72)

Fills the buffer with entropy bytes from std::random_device.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `seed` | `char *` | Buffer to fill. |
| `length` | `unsigned` | Number of bytes to write into seed. |

## Private Attributes

| Return | Name | Description |
|--------|------|-------------|
| `std::mt19937` | [`_engine`](#_engine)  |  |

---

<a id="_engine"></a>

### _engine

```cpp
std::mt19937 _engine
```

[Defined in src/base/include/icy/random.h:75](https://github.com/auscaster/icey/blob/main/src/base/include/icy/random.h#L75)
