randgen
randgen is a tool which generates random bytes using a pseudorandom number generator (PRNG).

Installation
From source
From binaries
The release page contains pre-built binaries for Linux, macOS and Windows.
How to build
Please see BUILD.adoc.
Usage
Basic usage
Generate 1 KiB of random bytes:
Output formats
The following output formats are available:
raw(encode the generated bytes as raw bytes)base64(encode the generated bytes as base64)base64url(encode the generated bytes as URL-safe base64)hex(encode the generated bytes as hex string)
[!TIP] The result is output on a single line, so there is no line wrapping.
The default output format is raw. To change this, use -f option.
This has the same result as:
|
Supported PRNGs and CSPRNGs
Supported PRNGs are:
- ISAAC RNGs (if enabled at compile time)
- Mersenne Twister RNGs (if enabled at compile time)
- PCG RNGs (if enabled at compile time)
- SFC RNGs (if enabled at compile time)
- Xorshift family
- SplitMix64 RNG
- Xorshift RNG (if enabled at compile time)
- xoroshiro RNGs
- xoshiro RNGs
Supported CSPRNGs are:
The default RNG is chacha12. To change this, use -r option.
Providing a random seed
-s option allows you to specify a 64-bit unsigned integer random seed to be
used when creating a new PRNG. If this option is not specified, the RNG seeded
via random data from system sources such as the getrandom system call on
Linux.
This has the same result as:
|
Print the progress bar
When -p option is specified, randgen will print information showing the
progress of the generation of random bytes.
This is similar to the following example which uses pv(1):
|
Generate shell completion
--generate-completion option generates shell completions to standard output.
The following shells are supported:
bashelvishfishnushellpowershellzsh
Example:
Integration with other programs
Encode the generated bytes
To encode the generated bytes into an output format not supported by randgen,
pipe the output of randgen to the input of another program.
For example, to encode the generated bytes as base32:
|
DYQZ33GRHUR5WIFRSBZVQ3ZPEFZASXB3SNTRUHR3NPITZBMDPZXQ====
Line wrapping
randgen does not wrap lines of the result.
To wrap lines of the result:
|
Hr1yramxGwVm88LXhA8=
This has the same result as:
|
Hr1yramxGwVm88LXhA8=
Comparison with similar things
The following generates 64 KiB of random bytes and encodes it as base64:
This section describes how to do the same thing with other things.
OpenSSL
openssl-rand(1ssl) can be used for this purpose.
GnuPG
gpg --gen-random can be used for this purpose.
|
Kernel random number source devices
random(4) (/dev/random and /dev/urandom) can be used for this purpose.
|
[!CAUTION] Unlike
randgen, these things wrap lines of the result.
Command-line options
Please see the following:
Source code
The upstream repository is available at https://github.com/sorairolake/randgen.git.
Changelog
Please see CHANGELOG.adoc.
Contributing
Please see CONTRIBUTING.adoc.
License
Copyright (C) 2025 Shun Sakai (see AUTHORS.adoc)
- This program is distributed under the terms of either the Apache License 2.0 or the MIT License.
- Some files are distributed under the terms of the Creative Commons Attribution 4.0 International Public License.
This project is compliant with version 3.3 of the REUSE Specification. See copyright notices of individual files for more details on copyright and licensing information.