coreutils: Random sources
1
1 2.7 Sources of random data
1 ==========================
1
1 The ‘shuf’, ‘shred’, and ‘sort’ commands sometimes need random data to
1 do their work. For example, ‘sort -R’ must choose a hash function at
1 random, and it needs random data to make this selection.
1
1 By default these commands use an internal pseudo-random generator
1 initialized by a small amount of entropy, but can be directed to use an
1 external source with the ‘--random-source=FILE’ option. An error is
1 reported if FILE does not contain enough bytes.
1
1 For example, the device file ‘/dev/urandom’ could be used as the
1 source of random data. Typically, this device gathers environmental
1 noise from device drivers and other sources into an entropy pool, and
1 uses the pool to generate random bits. If the pool is short of data,
1 the device reuses the internal pool to produce more bits, using a
1 cryptographically secure pseudo-random number generator. But be aware
1 that this device is not designed for bulk random data generation and is
1 relatively slow.
1
1 ‘/dev/urandom’ suffices for most practical uses, but applications
1 requiring high-value or long-term protection of private data may require
1 an alternate data source like ‘/dev/random’ or ‘/dev/arandom’. The set
1 of available sources depends on your operating system.
1
1 To reproduce the results of an earlier invocation of a command, you
1 can save some random data into a file and then use that file as the
1 random source in earlier and later invocations of the command. Rather
1 than depending on a file, one can generate a reproducible arbitrary
1 amount of pseudo-random data given a seed value, using for example:
1
1 get_seeded_random()
1 {
1 seed="$1"
1 openssl enc -aes-256-ctr -pass pass:"$seed" -nosalt \
1 </dev/zero 2>/dev/null
1 }
1
1 shuf -i1-100 --random-source=<(get_seeded_random 42)
1