A parallel random number generator utility built on the ranx library. This command-line tool provides functionality similar to the Ubuntu rand utility but leverages the high-performance, reproducible random number generation capabilities of the ranx library.
- Fast parallel random number generation using the PCG family of generators
- Reproducible sequences across all platforms when using the same seed
- Multiple output formats: integers, floats, unique values
- Flexible formatting: custom delimiters and output boundaries
- High-quality randomness using PCG32 engine with TRNG distributions
The utility is built automatically when building the ranx library (unless disabled):
cmake -S . -B build
cmake --build build -jTo disable building the utility:
cmake -S . -B build -DRANX_BUILD_UTILITY=OFFcmake --install buildThis installs the ranx executable to your system's binary directory (typically /usr/local/bin).
ranx [OPTION]
-N count- Number of random numbers to generate (default: 1)-L, --min number- The lower limit of the random numbers (default=0)-M, --max number- The upper limit of the random numbers (default: 32576)-u, --unique- Generate unique numbers without duplicates-f- Generate floating-point numbers between 0 and 1-p precision- Set decimal precision for floats (activates-f)-s number- Set the random seed (default: current time)-d STRING- Delimiter between numbers (default: space)--bof STRING- String to print at the beginning--eof STRING- String to print at the end (default: newline)--help- Display help message--version- Show version information
Generate 10 random numbers:
ranx -N 10Generate 5 numbers from 0 to 100 (closed range):
ranx -N 5 -M 100Generate 10 unique numbers from 10 to 20 (closed range):
ranx -N 10 -u -L 10 -M 20Generate 5 floating-point numbers with 4 decimal places:
ranx -f -p 4 -N 5Generate numbers separated by commas:
ranx -N 5 -d ", "Generate reproducible sequence with a specific seed:
ranx -N 10 -s 42Format as a JSON array:
ranx -N 5 -d ", " --bof "[" --eof "]"The utility uses the PCG32 (Permuted Congruential Generator) engine from the PCG family, which provides:
- Excellent statistical properties
- Fast generation speed
- Small state size
- Reproducible sequences
- Integers: Uses
trng::uniform_int_distfor uniform integer distribution - Floats: Uses
trng::uniform01_distfor uniform distribution between 0 and 1 - Unique values: Uses Fisher-Yates shuffle via
std::shufflewith PCG32 (not parallel yet)
When you provide the same seed with -s, the utility guarantees identical output on all supported platforms (Linux/macOS/Windows):
$ ranx -N 5 -s 123
27606 20324 14982 6188 27424
$ ranx -N 5 -s 123
27606 20324 14982 6188 27424This implementation provides similar functionality to the Ubuntu rand utility with some enhancements:
- Command-line interface and option names
- Support for integer and float generation
- Custom delimiters and formatting options
- Seed-based reproducibility
- Does support a new flag for the low limit (
-L/--minflags) - Uses high-quality PCG32 engine (vs. standard C library RNG)
- Built on the ranx parallel generation library
- Does not support backslash escape interpretation (
-e/-Eflags) - Does not support mask formatting (
--maskflag)
MIT License - Copyright (c) 2025 Armin Sobhani