Skip to article frontmatterSkip to article content

Ranx Command Line Tool

A parallel random number generator utility


Ranx command line tool is a parallel random number generator utility built on the Ranx library. It provides functionality similar to the Ubuntu rand utility but leverages the high-performance, reproducible random number generation capabilities of the Ranx library.

Features

Building

The utility is built automatically when building the Ranx library (unless disabled):

cmake -S . -B build
cmake --build build -j

To disable building the utility:

cmake -S . -B build -DRANX_BUILD_UTILITY=OFF

Installation

cmake --install build

This installs the ranx executable to your system’s binary directory (typically /usr/local/bin).

Usage

ranx [OPTION]

Options

Examples

Generate 10 random numbers:

!ranx -N 10
Output
5278 3664 13264 19241 8205 12455 2035 18563 21814 24187

Generate 5 numbers from 0 to 100 (closed range):

!ranx -N 5 -M 100
Output
88 74 60 61 2

Generate 10 unique numbers from 10 to 20 (closed range):

!ranx -N 10 -u -L 10 -M 20
Output
20 18 17 12 11 13 14 19 16 10

Generate 5 floating-point numbers with 4 decimal places:

!ranx -f -p 4 -N 5
Output
0.1297 0.8652 0.7456 0.4184 0.0218

Generate numbers separated by commas:

!ranx -N 5 -d ", "
Output
26483, 29423, 27826, 30380, 12425

Generate reproducible sequence with a specific seed:

!ranx -N 10 -s 42
Output
24808 13619 14597 8669 31263 13328 25930 27223 15641 32458

Format as a JSON array:

!ranx -N 5 -d ", " --bof "[" --eof "]"
Output
[17493, 30869, 16604, 18438, 11029]

Technical Details

Random Number Engine

The utility uses the PCG32 (Permuted Congruential Generator) engine from the PCG family, which provides:

Distributions

Reproducibility

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
Output
27606 20324 14982 6188 27424

Comparison with Ubuntu rand

This implementation provides similar functionality to the Ubuntu rand utility with some enhancements:

Similarities

Differences

License

MIT License - Copyright (c) 2025 Armin Sobhani

See Also