{
    "mode": "man",
    "parameter": "random",
    "section": "4",
    "url": "https://www.chedong.com/phpMan.php/man/random/4/json",
    "generated": "2026-09-13T09:34:56Z",
    "synopsis": "#include <linux/random.h>\nint ioctl(fd, RNDrequest, param);",
    "sections": {
        "NAME": {
            "content": "random, urandom - kernel random number source devices\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "#include <linux/random.h>\n\nint ioctl(fd, RNDrequest, param);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The character special files /dev/random and /dev/urandom (present since Linux 1.3.30) provide\nan  interface to the kernel's random number generator.  The file /dev/random has major device\nnumber 1 and minor device number 8.  The file /dev/urandom has major device number 1 and  mi‐\nnor device number 9.\n\nThe random number generator gathers environmental noise from device drivers and other sources\ninto an entropy pool.  The generator also keeps an estimate of the number of bits of noise in\nthe entropy pool.  From this entropy pool, random numbers are created.\n\nLinux  3.17 and later provides the simpler and safer getrandom(2) interface which requires no\nspecial files; see the getrandom(2) manual page for details.\n\nWhen read, the /dev/urandom device returns random bytes using a pseudorandom number generator\nseeded from the entropy pool.  Reads from this device do not block  (i.e.,  the  CPU  is  not\nyielded), but can incur an appreciable delay when requesting large amounts of data.\n\nWhen  read during early boot time, /dev/urandom may return data prior to the entropy pool be‐\ning initialized.  If this is of concern in your application, use getrandom(2) or  /dev/random\ninstead.\n\nThe  /dev/random  device  is  a legacy interface which dates back to a time where the crypto‐\ngraphic primitives used in the implementation of /dev/urandom were not  widely  trusted.   It\nwill  return  random bytes only within the estimated number of bits of fresh noise in the en‐\ntropy pool, blocking if necessary.  /dev/random is suitable for applications that  need  high\nquality randomness, and can afford indeterminate delays.\n\nWhen  the  entropy pool is empty, reads from /dev/random will block until additional environ‐\nmental noise is gathered.  Since Linux 5.6, the ONONBLOCK flag  is  ignored  as  /dev/random\nwill  no  longer  block except during early boot process.  In earlier versions, if open(2) is\ncalled for /dev/random with the ONONBLOCK flag, a subsequent read(2) will not block  if  the\nrequested  number  of bytes is not available.  Instead, the available bytes are returned.  If\nno byte is available, read(2) will return -1 and errno will be set to EAGAIN.\n\nThe ONONBLOCK flag has no effect when opening /dev/urandom.  When calling  read(2)  for  the\ndevice  /dev/urandom, reads of up to 256 bytes will return as many bytes as are requested and\nwill not be interrupted by a signal handler.  Reads with a buffer over this limit may  return\nless  than  the  requested  number of bytes or fail with the error EINTR, if interrupted by a\nsignal handler.\n\nSince Linux 3.16, a read(2) from /dev/urandom will return at  most  32 MB.   A  read(2)  from\n/dev/random will return at most 512 bytes (340 bytes before Linux 2.6.12).\n\nWriting  to  /dev/random  or /dev/urandom will update the entropy pool with the data written,\nbut this will not result in a higher entropy count.  This means that it will impact the  con‐\ntents read from both files, but it will not make reads from /dev/random faster.\n",
            "subsections": [
                {
                    "name": "Usage",
                    "content": "The /dev/random interface is considered a legacy interface, and /dev/urandom is preferred and\nsufficient in all use cases, with the exception of applications which require randomness dur‐\ning  early  boot  time; for these applications, getrandom(2) must be used instead, because it\nwill block until the entropy pool is initialized.\n\nIf a seed file is saved across reboots as recommended below, the output is  cryptographically\nsecure  against attackers without local root access as soon as it is reloaded in the boot se‐\nquence, and perfectly adequate for network encryption session keys.  (All major Linux distri‐\nbutions have saved the seed file across reboots since  2000  at  least.)   Since  reads  from\n/dev/random  may  block, users will usually want to open it in nonblocking mode (or perform a\nread with timeout), and provide some sort of user notification if the desired entropy is  not\nimmediately available.\n"
                },
                {
                    "name": "Configuration",
                    "content": "If  your  system does not have /dev/random and /dev/urandom created already, they can be cre‐\nated with the following commands:\n\nmknod -m 666 /dev/random c 1 8\nmknod -m 666 /dev/urandom c 1 9\nchown root:root /dev/random /dev/urandom\n\nWhen a Linux system starts up without much operator interaction, the entropy pool may be in a\nfairly predictable state.  This reduces the actual amount of noise in the entropy pool  below\nthe estimate.  In order to counteract this effect, it helps to carry entropy pool information\nacross shut-downs and start-ups.  To do this, add the lines to an appropriate script which is\nrun during the Linux system start-up sequence:\n\necho \"Initializing random number generator...\"\nrandomseed=/var/run/random-seed\n# Carry a random seed from start-up to start-up\n# Load and then save the whole entropy pool\nif [ -f $randomseed ]; then\ncat $randomseed >/dev/urandom\nelse\ntouch $randomseed\nfi\nchmod 600 $randomseed\npoolfile=/proc/sys/kernel/random/poolsize\n[ -r $poolfile ] && bits=$(cat $poolfile) || bits=4096\nbytes=$(expr $bits / 8)\ndd if=/dev/urandom of=$randomseed count=1 bs=$bytes\n\nAlso,  add  the following lines in an appropriate script which is run during the Linux system\nshutdown:\n\n# Carry a random seed from shut-down to start-up\n# Save the whole entropy pool\necho \"Saving random seed...\"\nrandomseed=/var/run/random-seed\ntouch $randomseed\nchmod 600 $randomseed\npoolfile=/proc/sys/kernel/random/poolsize\n[ -r $poolfile ] && bits=$(cat $poolfile) || bits=4096\nbytes=$(expr $bits / 8)\ndd if=/dev/urandom of=$randomseed count=1 bs=$bytes\n\nIn the above examples, we assume Linux 2.6.0 or later, where /proc/sys/kernel/random/poolsize\nreturns the size of the entropy pool in bits (see below).\n"
                },
                {
                    "name": "/proc interfaces",
                    "content": "The files in the directory /proc/sys/kernel/random (present since Linux 2.3.16) provide addi‐\ntional information about the /dev/random device:\n\nentropyavail\nThis read-only file gives the available entropy, in bits.  This will be  a  number  in\nthe range 0 to 4096.\n\npoolsize\nThis  file gives the size of the entropy pool.  The semantics of this file vary across\nkernel versions:\n\nLinux 2.4:\nThis file gives the size of the entropy pool in  bytes.   Normally,  this  file\nwill  have  the  value 512, but it is writable, and can be changed to any value\nfor which an algorithm is available.  The choices are 32, 64,  128,  256,  512,\n1024, or 2048.\n\nLinux 2.6 and later:\nThis  file  is  read-only,  and gives the size of the entropy pool in bits.  It\ncontains the value 4096.\n\nreadwakeupthreshold\nThis file contains the number of bits of entropy required for waking up processes that\nsleep waiting for entropy from /dev/random.  The default is 64.\n\nwritewakeupthreshold\nThis file contains the number of bits of entropy below which we wake up processes that\ndo a select(2) or poll(2) for write  access  to  /dev/random.   These  values  can  be\nchanged by writing to the files.\n\nuuid and bootid\nThese        read-only       files       contain       random       strings       like\n6fd5a44b-35f4-4ad4-a9b9-6b9be13e1fe9.  The former is generated afresh for  each  read,\nthe latter was generated once.\n"
                },
                {
                    "name": "ioctl(2) interface",
                    "content": "The following ioctl(2) requests are defined on file descriptors connected to either /dev/ran‐\ndom  or  /dev/urandom.   All requests performed will interact with the input entropy pool im‐\npacting both /dev/random and /dev/urandom.  The CAPSYSADMIN capability is required for  all\nrequests except RNDGETENTCNT.\n\nRNDGETENTCNT\nRetrieve the entropy count of the input pool, the contents will be the same as the en‐\ntropyavail  file  under proc.  The result will be stored in the int pointed to by the\nargument.\n\nRNDADDTOENTCNT\nIncrement or decrement the entropy count of the input pool by the value pointed to  by\nthe argument.\n\nRNDGETPOOL\nRemoved in Linux 2.6.9.\n\nRNDADDENTROPY\nAdd  some  additional entropy to the input pool, incrementing the entropy count.  This\ndiffers from writing to /dev/random or /dev/urandom, which only  adds  some  data  but\ndoes not increment the entropy count.  The following structure is used:\n\nstruct randpoolinfo {\nint    entropycount;\nint    bufsize;\nu32  buf[0];\n};\n\nHere  entropycount  is the value added to (or subtracted from) the entropy count, and\nbuf is the buffer of size bufsize which gets added to the entropy pool.\n\nRNDZAPENTCNT\nRNDCLEARPOOL\nZero the entropy count of all pools and add some system data (such as wall  clock)  to\nthe pools.\n"
                }
            ]
        },
        "FILES": {
            "content": "/dev/random\n/dev/urandom\n",
            "subsections": []
        },
        "NOTES": {
            "content": "For  an  overview and comparison of the various interfaces that can be used to obtain random‐\nness, see random(7).\n",
            "subsections": []
        },
        "BUGS": {
            "content": "During early boot time, reads from /dev/urandom may return data prior to the entropy pool be‐\ning initialized.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "mknod(1), getrandom(2), random(7)\n\nRFC 1750, \"Randomness Recommendations for Security\"\n\nLinux man-pages 6.7                          2023-10-31                                    random(4)",
            "subsections": []
        }
    },
    "summary": "random, urandom - kernel random number source devices",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "mknod",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/mknod/1/json"
        },
        {
            "name": "getrandom",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/getrandom/2/json"
        }
    ]
}