Prefetch Technologies // Keeping your cache lines cozy

Creating a set of random numbers from the command line

This past weekend I was doing some database testing and needed to generate some random numbers to populate a table. My typical go-to utility for generating one random number is head piped to od and tr:

$ head -c 8 /dev/urandom | od -An -t x | tr -d ' '
3a366d317245d2ed

This works well and can be aded to a loop to get more than one number. But I was curious if there was a native Linux utility available to do this work. A quick poke through the Linux man pages turned up the coreutils shuf utility:

$ man -k random
pwmake (1)           - simple tool for generating random relatively easily
pronounceable passwords
shuf (1)             - generate random permutations
sslrand (1ssl)       - generate pseudo-random bytes
systemd-random-seed (8) - Load and save the system random seed at boot and
shutdown
systemd-random-seed.service (8) - Load and save the system random seed at boot
and shutdown
tc-red (8)           - Random Early Detection

This was exactly what I was after. You can use the "-i" option to indicate the random number range and "-n" to control how many numbers are returned:

$ shuf -i 1-10000000 -n 5
6174420
3403304
6024195
8451479
9210890

Super cool utility!