Skip to content

urandom

Practical examples, benchmarks, and creative uses of the Linux /dev/urandom non-blocking entropy source, including randomness generation, testing, and audio experimentation


Create Several Files Filled with Random Data

for fileSize in 1 10 50 100 250 500 1000; do 
    echo "Creating file: ${fileSize}M"; 
    sudo head -c ${fileSize}M </dev/urandom >${fileSize}; 
done

Create a File with Random Data Using 'head' Command

head -c 50M </dev/urandom >50MB

Create a File with Random Data Using OpenSSL

openssl rand -out sample.txt -base64 $(( 2**30 * 3/4 ))
openssl rand -base64 1000 | dd of=sample.txt bs=1G count=1

Generate deterministic pseudo-random numbers using a seed-derived OpenSSL stream

get_seeded_random()
    {
      seed="$1"
      openssl enc -aes-256-ctr -pass pass:"$seed" -nosalt \
        </dev/zero 2>/dev/null
    }
    
shuf -i1-100 --random-source=<(get_seeded_random 42)

Generate a random MAC address (locally administered)

printf '02:%02x:%02x:%02x:%02x:%02x\n' $(od -An -N5 -tx1 /dev/urandom)

Create a random filename-safe token

head -c 16 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c 22

Random delay jitter (anti-fingerprinting / testing)

sleep "$(od -An -N2 -tu2 /dev/urandom | awk '{print $1/50000}')"

Generate a random IPv6 address

printf '%x:%x:%x:%x:%x:%x:%x:%x\n' $(od -An -N16 -tx2 /dev/urandom)

Visual entropy density

hexdump -n 256 -C /dev/urandom

Introduce visible random sleep jitter derived from /dev/urandom

t=$(od -An -N2 -tu2 /dev/urandom | awk '{printf "%.3f\n", $1/50000}')
echo "Sleeping for $t seconds"
sleep "$t"

Read raw entropy

od -An -N2 -tu2 /dev/urandom

Randomize execution order of commands

printf '%s\n' cmd1 cmd2 cmd3 cmd4 | shuf --random-source=/dev/urandom

Generate a 13-character random password from /dev/urandom

head -c 500 /dev/urandom | tr -dc 'a-zA-Z0-9~!@#$%^&*_-' | fold -w 13 | head -n 1

Generate random numbers using /dev/urandom as an explicit entropy source

shuf --random-source='/dev/urandom' -n 100 -i 1-5 | perl -pe 's/\n/ /g;';

Benchmark raw entropy throughput from /dev/urandom

time cat /dev/urandom | head -c 1000000000 > /dev/null

Recognized numbers only by od and /dev/urandom

od -d /dev/urandom

Generate a small file from the non-blocking entropy source (/dev/urandom)

dd if=/dev/urandom of=~/urandom_test count=4 bs=1024

Read 30 random bytes into a file random.bytes

head -c 30 /dev/urandom > random.bytes

Viewing raw entropy bytes from /dev/urandom

cat /dev/urandom | hexdump

Play raw entropy noise via default audio backend

cat /dev/urandom | play -q -t raw -r 8000 -e unsigned-integer -b 8 -c 1 -

Play raw entropy noise via ALSA (bypass PulseAudio/PipeWire)

cat /dev/urandom | play -q -t raw -r 8000 -e unsigned-integer -b 8 -c 1 -t alsa default

Play filtered entropy noise (low-pass, ambient)

cat /dev/urandom | play -q -t raw -r 8000 -e unsigned-integer -b 8 -c 1 - lowpass 600 vol 0.05

Speed it up for harsh data storm

cat /dev/urandom | play -q -t raw -r 22050 -e unsigned-integer -b 8 -c 1 - vol 0.03