# Randomness
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-9)</span>

All draw methods are partial: they error during replay when the recorded
choice sequence is exhausted or when a type/range mismatch is detected.
In plain mode (user-constructed Randomness), draws never error.

Integer methods generate values in the closed interval [min, max].
Floating-point methods scale onto [min, max]; `min` is always reachable,
`max` is an approximate upper bound due to floating-point rounding.


```pony
class ref Randomness
```

## Constructors

### create
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-29)</span>


```pony
new ref create(
  seed1: U64 val = 42,
  seed2: U64 val = 0)
: Randomness ref^
```
#### Parameters

*   seed1: [U64](builtin-U64.md) val = 42
*   seed2: [U64](builtin-U64.md) val = 0

#### Returns

* [Randomness](pony_check-Randomness.md) ref^

---

## Public Functions

### u8
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-33)</span>


Generate a U8 in closed interval [min, max].


```pony
fun ref u8(
  min: U8 val = U8.min_value(),
  max: U8 val = U8.max_value())
: U8 val ?
```
#### Parameters

*   min: [U8](builtin-U8.md) val = U8.min_value()
*   max: [U8](builtin-U8.md) val = U8.max_value()

#### Returns

* [U8](builtin-U8.md) val ?

---

### u16
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-39)</span>


Generate a U16 in closed interval [min, max].


```pony
fun ref u16(
  min: U16 val = U16.min_value(),
  max: U16 val = U16.max_value())
: U16 val ?
```
#### Parameters

*   min: [U16](builtin-U16.md) val = U16.min_value()
*   max: [U16](builtin-U16.md) val = U16.max_value()

#### Returns

* [U16](builtin-U16.md) val ?

---

### u32
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-45)</span>


Generate a U32 in closed interval [min, max].


```pony
fun ref u32(
  min: U32 val = U32.min_value(),
  max: U32 val = U32.max_value())
: U32 val ?
```
#### Parameters

*   min: [U32](builtin-U32.md) val = U32.min_value()
*   max: [U32](builtin-U32.md) val = U32.max_value()

#### Returns

* [U32](builtin-U32.md) val ?

---

### u64
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-51)</span>


Generate a U64 in closed interval [min, max].


```pony
fun ref u64(
  min: U64 val = U64.min_value(),
  max: U64 val = U64.max_value())
: U64 val ?
```
#### Parameters

*   min: [U64](builtin-U64.md) val = U64.min_value()
*   max: [U64](builtin-U64.md) val = U64.max_value()

#### Returns

* [U64](builtin-U64.md) val ?

---

### u128
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-57)</span>


Generate a U128 in closed interval [min, max].


```pony
fun ref u128(
  min: U128 val = U128.min_value(),
  max: U128 val = U128.max_value())
: U128 val ?
```
#### Parameters

*   min: [U128](builtin-U128.md) val = U128.min_value()
*   max: [U128](builtin-U128.md) val = U128.max_value()

#### Returns

* [U128](builtin-U128.md) val ?

---

### ulong
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-67)</span>


Generate a ULong in closed interval [min, max].


```pony
fun ref ulong(
  min: ULong val = ULong.min_value(),
  max: ULong val = ULong.max_value())
: ULong val ?
```
#### Parameters

*   min: [ULong](builtin-ULong.md) val = ULong.min_value()
*   max: [ULong](builtin-ULong.md) val = ULong.max_value()

#### Returns

* [ULong](builtin-ULong.md) val ?

---

### usize
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-77)</span>


Generate a USize in closed interval [min, max].


```pony
fun ref usize(
  min: USize val = USize.min_value(),
  max: USize val = USize.max_value())
: USize val ?
```
#### Parameters

*   min: [USize](builtin-USize.md) val = USize.min_value()
*   max: [USize](builtin-USize.md) val = USize.max_value()

#### Returns

* [USize](builtin-USize.md) val ?

---

### i8
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-87)</span>


Generate an I8 in closed interval [min, max].


```pony
fun ref i8(
  min: I8 val = I8.min_value(),
  max: I8 val = I8.max_value())
: I8 val ?
```
#### Parameters

*   min: [I8](builtin-I8.md) val = I8.min_value()
*   max: [I8](builtin-I8.md) val = I8.max_value()

#### Returns

* [I8](builtin-I8.md) val ?

---

### i16
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-93)</span>


Generate an I16 in closed interval [min, max].


```pony
fun ref i16(
  min: I16 val = I16.min_value(),
  max: I16 val = I16.max_value())
: I16 val ?
```
#### Parameters

*   min: [I16](builtin-I16.md) val = I16.min_value()
*   max: [I16](builtin-I16.md) val = I16.max_value()

#### Returns

* [I16](builtin-I16.md) val ?

---

### i32
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-99)</span>


Generate an I32 in closed interval [min, max].


```pony
fun ref i32(
  min: I32 val = I32.min_value(),
  max: I32 val = I32.max_value())
: I32 val ?
```
#### Parameters

*   min: [I32](builtin-I32.md) val = I32.min_value()
*   max: [I32](builtin-I32.md) val = I32.max_value()

#### Returns

* [I32](builtin-I32.md) val ?

---

### i64
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-105)</span>


Generate an I64 in closed interval [min, max].


```pony
fun ref i64(
  min: I64 val = I64.min_value(),
  max: I64 val = I64.max_value())
: I64 val ?
```
#### Parameters

*   min: [I64](builtin-I64.md) val = I64.min_value()
*   max: [I64](builtin-I64.md) val = I64.max_value()

#### Returns

* [I64](builtin-I64.md) val ?

---

### i128
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-111)</span>


Generate an I128 in closed interval [min, max].


```pony
fun ref i128(
  min: I128 val = I128.min_value(),
  max: I128 val = I128.max_value())
: I128 val ?
```
#### Parameters

*   min: [I128](builtin-I128.md) val = I128.min_value()
*   max: [I128](builtin-I128.md) val = I128.max_value()

#### Returns

* [I128](builtin-I128.md) val ?

---

### ilong
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-121)</span>


Generate an ILong in closed interval [min, max].


```pony
fun ref ilong(
  min: ILong val = ILong.min_value(),
  max: ILong val = ILong.max_value())
: ILong val ?
```
#### Parameters

*   min: [ILong](builtin-ILong.md) val = ILong.min_value()
*   max: [ILong](builtin-ILong.md) val = ILong.max_value()

#### Returns

* [ILong](builtin-ILong.md) val ?

---

### isize
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-131)</span>


Generate an ISize in closed interval [min, max].


```pony
fun ref isize(
  min: ISize val = ISize.min_value(),
  max: ISize val = ISize.max_value())
: ISize val ?
```
#### Parameters

*   min: [ISize](builtin-ISize.md) val = ISize.min_value()
*   max: [ISize](builtin-ISize.md) val = ISize.max_value()

#### Returns

* [ISize](builtin-ISize.md) val ?

---

### f32
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-141)</span>


Generate an F32 in the range from `min` to `max`.


```pony
fun ref f32(
  min: F32 val = 0.0,
  max: F32 val = 1.0)
: F32 val ?
```
#### Parameters

*   min: [F32](builtin-F32.md) val = 0.0
*   max: [F32](builtin-F32.md) val = 1.0

#### Returns

* [F32](builtin-F32.md) val ?

---

### f64
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-147)</span>


Generate an F64 in the range from `min` to `max`.


```pony
fun ref f64(
  min: F64 val = 0.0,
  max: F64 val = 1.0)
: F64 val ?
```
#### Parameters

*   min: [F64](builtin-F64.md) val = 0.0
*   max: [F64](builtin-F64.md) val = 1.0

#### Returns

* [F64](builtin-F64.md) val ?

---

### bool
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-153)</span>


Generate a random Bool value.


```pony
fun ref bool()
: Bool val ?
```

#### Returns

* [Bool](builtin-Bool.md) val ?

---

### forced_bool
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-179)</span>


Record a predetermined Bool. The shrinker will not attempt to
change this choice. Use when the outcome is fixed by the
generator's structure (e.g., elements below a collection minimum).


```pony
fun ref forced_bool(
  value: Bool val)
: Bool val ?
```
#### Parameters

*   value: [Bool](builtin-Bool.md) val

#### Returns

* [Bool](builtin-Bool.md) val ?

---

### shuffle\[T: T\]
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-205)</span>


Shuffle the array in place using Fisher-Yates, recording one integer
choice per element as the swap index.


```pony
fun ref shuffle[T: T](
  array: Array[T] ref)
: None val ?
```
#### Parameters

*   array: [Array](builtin-Array.md)\[T\] ref

#### Returns

* [None](builtin-None.md) val ?

---

### start_span
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-227)</span>


Mark the beginning of a structural span in the choice sequence.
Spans let the shrinker understand generator structure — for example,
which choices belong to a single collection element.


```pony
fun ref start_span(
  label: SpanLabel)
: None val
```
#### Parameters

*   label: [SpanLabel](pony_check-SpanLabel.md)

#### Returns

* [None](builtin-None.md) val

---

### end_span
<span class="source-link">[[Source]](src/pony_check/randomness.md#L-0-242)</span>


Close the most recently opened span. If `discard` is true, the span
is marked as discarded (e.g., a filter rejection).

Errors if no span is open (mismatched start_span/end_span calls).


```pony
fun ref end_span(
  discard: Bool val = false)
: None val ?
```
#### Parameters

*   discard: [Bool](builtin-Bool.md) val = false

#### Returns

* [None](builtin-None.md) val ?

---

