arc4random - Linux


Overview

The arc4random command is a secure and high-quality pseudorandom number generator (PRNG) built into macOS and Linux. It’s a portable implementation of the popular ARC4 cipher, known for its speed, unpredictability, and suitability for cryptographic applications.

Syntax

arc4random

Options/Flags

No options are available.

Examples

Generate a random integer:

$ arc4random
1234567890

Generate a range of integers:

$ for i in $(arc4random % 100); do echo $i; done
97
34
55
...

Generate a random character:

$ echo $(arc4random | od -An -t u1 1)

Common Issues

  • Secure usage: arc4random is a pseudorandom generator, not a true random generator. It should not be used for critical security applications where genuine randomness is essential.
  • Seeding: The initial seed for arc4random is derived from the system’s entropy pool. If the pool is weak, the generated numbers may be less random.

Integration

  • Use with other commands to create complex random sequences:
$ seq 1 10 | xargs arc4random -o
1234567890

Related Commands

  • random: Another built-in PRNG in macOS and Linux.
  • urandom: Linux pseudorandom generator that uses kernel entropy.
  • /dev/random: Linux device for generating truly random numbers (slow).