---
title: "generate random string · RUAL Documentation"
description: "Generates a cryptographically random string from an alphabet you choose. Use it for human-facing codes (claim, invite, voucher) where the alphabet has t…"
canonical: https://docs.rual.nl/block-types/value/value_random_string
language: en
---

# generate random string

This block is part of the [`value`](https://docs.rual.nl/block-types/value) group and was last modified in core [`v15.0.0`](https://docs.rual.nl/core-versions/150000).

Generates a cryptographically random string from an alphabet you choose. Use it for human-facing codes (claim, invite, voucher) where the alphabet has to exclude lookalike characters. Every character of the alphabet is equally likely.

- alphabet `value` The characters to pick from. Defaults to `0123456789ABCDEFGHJKLMNPQRSTUVWXYZ` : digits and uppercase letters without the lookalikes `I` and `O`.

Default `0123456789ABCDEFGHJKLMNPQRSTUVWXYZ`

- length `number` How many characters to generate. Maximum 4096.

Default `8`

- value `value`

- error `value` `NO_ALPHABET` when the alphabet is empty, `INVALID_LENGTH` when the length is zero or negative.

Uniform (rejection-sampled) crypto-random string from the given alphabet; the default alphabet is digits plus uppercase letters WITHOUT I and O. length defaults to 8 and is SILENTLY capped at 4096. Empty alphabet -> value "" and error "NO_ALPHABET"; zero or negative length -> value "" and error "INVALID_LENGTH"; on success error is nil.

| `random string` |
| --- |
| `random code` |
| `voucher code` |
| `claim code` |
| `custom shortid` |

A typical wiring for [generate random string](https://docs.rual.nl/block-types/value/value_random_string): [number](https://docs.rual.nl/block-types/number/number_default) feeds the `length` pin; [value](https://docs.rual.nl/block-types/value/value_default) feeds the `alphabet` pin; the `value` out pin feeds [convert to uppercase](https://docs.rual.nl/block-types/value/value_to_uppercase).

![Studio canvas example for the generate random string block: typical wiring for generate random string.](https://docs.rual.nl/canvas-examples/value_random_string.png)

### Commonly used with

In production blueprints, this block is most often wired together with:

- [set fields](https://docs.rual.nl/block-types/mutations/mutations_set_bp_field_multiple): this block feeds into it. Generates an array of mutations based on the given filled fields.

- [number](https://docs.rual.nl/block-types/number/number_default): feeds into this block. Generates a valid number from the filled custom value in the blueprint.

- [value](https://docs.rual.nl/block-types/value/value_default): feeds into this block. Simply returns the provided value.

### Version history

Introduced in [`v15.0.0`](https://docs.rual.nl/core-versions/150000).
