randgen - generate pseudo-random bytes
randgen is a tool which generates random bytes using a pseudorandom number generator (PRNG). The generated bytes will be output to standard output.
-
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
-
Important
|
Note that the number of bytes in the generated result may differ from the number of bytes specified in the BYTES positional argument. See the --format option for details. |
- BYTES
-
Number of bytes to generate. BYTES can be suffixed with the symbol (B) and the byte prefix (such as Ki and M). If only a numeric value is specified for BYTES, it is the same as specifying the symbol without the byte prefix.
- -f, --format FORMAT
-
Output in the specified output format.
- The possible values are:
-
- raw
-
Encode the generated bytes as raw bytes. This is the default value.
- base64
-
Encode the generated bytes as base64. The result is output on a single line, so there is no line wrapping. This value is available if the
base64
feature is enabled at compile time.WarningThe number of bytes in the generated base64 string will be approximately 33% larger than the number of bytes specified in the BYTES positional argument. - base64url
-
Encode the generated bytes as URL-safe base64. The result is output on a single line, so there is no line wrapping. This value is available if the
base64
feature is enabled at compile time.WarningThe number of bytes in the generated URL-safe base64 string will be approximately 33% larger than the number of bytes specified in the BYTES positional argument. - hex
-
Encode the generated bytes as hex string. The result is output on a single line, so there is no line wrapping. This value is available if the
hex
feature is enabled at compile time.WarningThe number of bytes in the generated hex string is twice the number of bytes specified in the BYTES positional argument.
- -r, --random-number-generator RNG
-
Random number generator to use.
- The possible values are:
-
- chacha8
-
A CSPRNG that uses the ChaCha8 algorithm.
- chacha12
-
A CSPRNG that uses the ChaCha12 algorithm. This is the default value.
- chacha20
-
A CSPRNG that uses the ChaCha20 algorithm.
- hc128
-
A CSPRNG that uses the HC-128 algorithm. This value is available if the
hc
feature is enabled at compile time. - isaac
-
A PRNG that uses the ISAAC algorithm. This value is available if the
isaac
feature is enabled at compile time. - isaac64
-
A PRNG that uses the ISAAC-64 algorithm. This value is available if the
isaac
feature is enabled at compile time. - mt
-
The MT19937 PRNG. This value is available if the
mt
feature is enabled at compile time. - mt64
-
The MT19937-64 PRNG. This value is available if the
mt
feature is enabled at compile time. - pcg32
-
The pcg32 PRNG. This value is available if the
pcg
feature is enabled at compile time. - pcg64
-
The pcg64 PRNG. This value is available if the
pcg
feature is enabled at compile time. - pcg64dxsm
-
The PCG64DXSM PRNG. This value is available if the
pcg
feature is enabled at compile time. - pcg64mcg
-
The pcg64_fast PRNG. This value is available if the
pcg
feature is enabled at compile time. - sfc32
-
The sfc32 PRNG. This value is available if the
sfc
feature is enabled at compile time. - sfc64
-
The sfc64 PRNG. This value is available if the
sfc
feature is enabled at compile time. - splitmix64
-
The splitmix64 PRNG.
- xorshift
-
The Xorshift PRNG. This value is available if the
xorshift
feature is enabled at compile time. - xoroshiro64*
-
The xoroshiro64* PRNG.
- xoroshiro64*
-
The xoroshiro64** PRNG.
- xoroshiro128+
-
The xoroshiro128+ PRNG.
- xoroshiro128++
-
The xoroshiro128++ PRNG.
- xoroshiro128**
-
The xoroshiro128** PRNG.
- xoshiro128+
-
The xoshiro128+ PRNG.
- xoshiro128++
-
The xoshiro128++ PRNG.
- xoshiro128**
-
The xoshiro128** PRNG.
- xoshiro256+
-
The xoshiro256+ PRNG.
- xoshiro256++
-
The xoshiro256++ PRNG.
- xoshiro256**
-
The xoshiro256** PRNG.
- xoshiro512+
-
The xoshiro512+ PRNG.
- xoshiro512++
-
The xoshiro512++ PRNG.
- xoshiro512**
-
The xoshiro512** PRNG.
- -s, --seed NUMBER
-
Random seed to use. If this option is not specified, the RNG seeded via random data from system sources such as the
getrandom
system call on Linux. - -p, --progress
-
Print information showing the progress of the output of the generated result. This progress bar does not indicate the progress of the generation of random bytes itself.
NoteThis option is ignored when the generated bytes are output to a terminal/tty. - -h, --help
-
Print help message. The short flag (-h) will print a condensed help message while the long flag (--help) will print a detailed help message.
- -V, --version
-
Print version number. The long flag (--version) will also print the copyright notice, the license notice and where to report bugs.
- --generate-completion SHELL
-
Generate shell completion. The completion is output to standard output.
- The possible values are:
-
- bash
-
Bash.
- elvish
-
Elvish.
- fish
-
fish.
- nushell
-
Nushell.
- powershell
-
PowerShell.
- zsh
-
Zsh.
- 0
-
Successful program execution.
- 1
-
An error occurred.
- 2
-
An error occurred while parsing command-line arguments.
Exit statuses other than these are defined by
<sysexits.h>
.
- Source repository:
- Generate 1 KiB of random bytes:
-
$ randgen 1KiB
- Encode the generated bytes as base64:
-
$ randgen -f base64 256
- Use the pcg64 as a PRNG:
-
$ randgen -r pcg64 "2 MB"
- Use the specified random seed:
-
$ randgen -f hex -r sfc32 -s 8 32B
- Report bugs to:
Copyright © 2025 Shun Sakai
-
This program is distributed under the terms of either the Apache License 2.0 or the MIT License.
-
This manual page is distributed under the terms of the Creative Commons Attribution 4.0 International Public License.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.