random(4)random(4)NAME
random, urandom - Kernel random number source devices
DESCRIPTION
The /dev/random and /dev/urandom character device special files provide
an interface to the kernel random number generator. The random number
generator gathers environmental data from device drivers and other
sources into an entropy pool. The generator keeps an estimate of the
number of bits of data in the entropy pool. Random numbers are gener‐
ated from this entropy pool.
Writing data to the /dev/random or /dev/urandom device will mix the new
data into the entrophy pool to make the random data better, but it will
not increase the entrophy estimate. This prevents a user from writing
lots of low-entrophy data to the pool and having the /dev/random device
generate poor random data.
FILES
A character device special file that provides an interface to the ker‐
nel random number generator. When read, the /dev/random file will
return only random bytes within the estimated number of bits of noise
in the entropy pool. This is suitable for uses that need high quality
randomness, such as one-time pad or key generation. If the entropy pool
is empty or does not contain enough bytes, reads to the /dev/random
file will be blocked until additional environment noise is gathered. A
character device special file that provides an interface to the kernel
random number generator. When read, the /dev/urandom file will return
as many random bytes as are requested. As a result, if there are not
sufficient bytes in the entropy pool, reads to the /dev/urandom will
not be blocked and the returned values are theoretically vulnerable to
a cryptographic attack on the algorithms used by the driver. If this is
a concern for your application, use the /dev/random device instead.
EXAMPLES
To generate a 16-byte random value and display it in hexadecimal char‐
acters, enter: % dd bs=16 count=1 < /dev/random | od -An -tx2 dfd5 7b74
0049 359f 35ed b2db e70d e629
To generate eight random printable characters, enter: % dd bs=10
count=10 < /dev/random | tr -cd '[:print:]' | head -c8 sHp3#t6w
To select 4 random words from a document, for example, Project Guten‐
berg's "Complete Works of Shakespeare" (this example is for csh),
enter: % tr -cs '[:alpha:]' '\n' < shaks12.txt > shaks12.temp % set
wc=`wc -l < shaks12.temp` % set words=(`dd bs=16 count=1 < /dev/random
| od -tu4 -An`) % set w1=`expr $words[1] % $wc + 1` % set w2=`expr
$words[2] % $wc + 1` % set w3=`expr $words[3] % $wc + 1` % set w4=`expr
$words[4] % $wc + 1` % sed -n -e "$w1 p" -e "$w2 p" -e "$w3 p" -e "$w4
p" < shaks12.temp wrested affected Cyprus least
LEGAL NOTICES
Derived from linux/drivers/char/random.c 2.4.0-test9
random.c -- A strong random number generator
Version 1.89, last modified 19-Sep-99
Copyright Theodore Ts'o, 1994, 1995, 1996, 1997, 1998, 1999. All
rights reserved.
Redistribution and use in source and binary forms, with or without mod‐
ification, are permitted provided that the following conditions are
met: Redistributions of source code must retain the above copyright
notice, and the entire permission notice in its entirety, including the
disclaimer of warranties. Redistributions in binary form must repro‐
duce the above copyright notice, this list of conditions and the fol‐
lowing disclaimer in the documentation and/or other materials provided
with the distribution. The name of the author may not be used to
endorse or promote products derived from this software without specific
prior written permission.
ALTERNATIVELY, this product may be distributed under the terms of the
GNU Public License, in which case the provisions of the GPL are
required INSTEAD OF the above restrictions. (This clause is necessary
due to a potential bad interaction between the GPL and the restrictions
contained in a BSD-style copyright.)
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WAR‐
RANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER‐
CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF WHICH ARE
HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAM‐
AGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOW‐
EVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSI‐
BILITY OF SUCH DAMAGE.
random(4)