# Generator

`import { Generator } from "destack:fuzz";`

Value generator.

```ds title="Generator"
export class Generator<T> {
    static bool(): Generator<boolean>;
    static int32(range?: RangeBounds<int32> | undefined): Generator<int32>;
    static uint32(range?: RangeBounds<uint32> | undefined): Generator<uint32>;
    static int64(range?: RangeBounds<int64> | undefined): Generator<int64>;
    static uint64(range?: RangeBounds<uint64> | undefined): Generator<uint64>;
    static float64(options?: FloatOptions | undefined): Generator<float64>;
    static string(options?: StringOptions | undefined): Generator<string>;
    static array<T>(options: ArrayOptions<T>): Generator<T[]>;
    static fromSchema<T>(schema: &'a readonly Schema<T>): Generator<T>;
    static constant<T>(value: T): Generator<T>;
    static oneOf<T>(generators: [Generator<T>]): Generator<T>;
    static weighted<T>(choices: [Weight<T>]): Generator<T>;
    optional(): Generator<T | undefined>;
    map<U>(body: (T) => U): Generator<U>;
    flatMap<U>(body: (T) => Generator<U>): Generator<U>;
    filter(predicate: (T) => boolean): Generator<T>;
    and<U>(other: Generator<U>): Generator<(T, U)>;
    shrink(value: T): Generator<T>;
}
```

[language/library/src/fuzz/generator.ds:29:119](https://github.com/destack-sh/destack/blob/main/language/library/src/fuzz/generator.ds#L29-L119)

## Members

### `static bool(): Generator<boolean>`

Generate boolean values.

### `static int32(range?: RangeBounds<int32> | undefined): Generator<int32>`

Generate signed 32-bit integers.

### `static uint32(range?: RangeBounds<uint32> | undefined): Generator<uint32>`

Generate unsigned 32-bit integers.

### `static int64(range?: RangeBounds<int64> | undefined): Generator<int64>`

Generate signed 64-bit integers.

### `static uint64(range?: RangeBounds<uint64> | undefined): Generator<uint64>`

Generate unsigned 64-bit integers.

### `static float64(options?: FloatOptions | undefined): Generator<float64>`

Generate floating-point values.

### `static string(options?: StringOptions | undefined): Generator<string>`

Generate strings.

### `static array<T>(options: ArrayOptions<T>): Generator<T[]>`

Generate arrays.

### `static fromSchema<T>(schema: &'a readonly Schema<T>): Generator<T>`

Generate values from a schema.

### `static constant<T>(value: T): Generator<T>`

Generate one constant value.

### `static oneOf<T>(generators: [Generator<T>]): Generator<T>`

Generate one value from `generators`.

### `static weighted<T>(choices: [Weight<T>]): Generator<T>`

Generate one value from weighted choices.

### `optional(): Generator<T | undefined>`

Generate optional values.

### `map<U>(body: (T) => U): Generator<U>`

Map generated values.

### `flatMap<U>(body: (T) => Generator<U>): Generator<U>`

Generate another value from each generated value.

### `filter(predicate: (T) => boolean): Generator<T>`

Keep generated values that match `predicate`.

### `and<U>(other: Generator<U>): Generator<(T, U)>`

Generate a pair from this generator and `other`.

### `shrink(value: T): Generator<T>`

Shrink `value` toward simpler generated values.
