Index Index for
Section 4
Index Alphabetical
listing for R
Bottom of page Bottom of
page

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 generated 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

/dev/random A character device special file that provides an interface to the kernel 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. /dev/urandom 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

1. To generate a 16-byte random value and display it in hexadecimal characters, enter: % dd bs=16 count=1 < /dev/random | od -An -tx2 dfd5 7b74 0049 359f 35ed b2db e70d e629 2. To generate eight random printable characters, enter: % dd bs=10 count=10 < /dev/random | tr -cd '[:print:]' | head -c8 sHp3#t6w 3. To select 4 random words from a document, for example, Project Gutenberg'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 modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, and the entire permission notice in its entirety, including the disclaimer of warranties. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. 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 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 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 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 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 POSSIBILITY OF SUCH DAMAGE.

Index Index for
Section 4
Index Alphabetical
listing for R
Top of page Top of
page