arc4random_buf - Linux


The arc4random_buf command generates cryptographically secure random bytes using the ARC4 random number generator. It is particularly useful in scenarios requiring high-quality randomness, such as generating keys, passwords, or other sensitive data.


arc4random_buf [-b bytes] [-o file]


  • -b bytes: specifies the number of bytes to generate. If omitted, defaults to 32 bytes.
  • -o file: specifies the file to write the random bytes to. If omitted, the bytes are written to standard output.


  • Generate 100 random bytes and write them to random.bin:
arc4random_buf -o random.bin -b 100
  • Generate 512-bit random key:
arc4random_buf -b 512 | base64 -w 0

Common Issues

  • Insufficient randomness: The ARC4 algorithm is not considered cryptographically strong. For applications requiring very high levels of security, consider using alternatives like /dev/urandom.
  • Bias: ARC4 does not guarantee uniform distribution of random numbers. For critical applications, use stronger and more recent random number generators (RNGs).


  • Integrate with openssl, gpg, and other crypto tools that require random data.
  • Use within scripts or pipelines to generate random values or populate data structures.

Related Commands

  • openssl rand: Another random number generator tool
  • /dev/urandom: Device file providing cryptographically secure random data
  • rngd: Random number generator daemon