Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


drand48(3) — Linux manual page

NAME |LIBRARY |SYNOPSIS |DESCRIPTION |ATTRIBUTES |STANDARDS |HISTORY |SEE ALSO |COLOPHON

drand48(3)               Library Functions Manualdrand48(3)

NAME        top

       drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48,       seed48, lcong48 - generate uniformly distributed pseudo-random       numbers

LIBRARY        top

       Standard C library (libc,-lc)

SYNOPSIS        top

#include <stdlib.h>double drand48(void);double erand48(unsigned shortxsubi[3]);long lrand48(void);long nrand48(unsigned shortxsubi[3]);long mrand48(void);long jrand48(unsigned shortxsubi[3]);void srand48(longseedval);unsigned short *seed48(unsigned shortseed16v[3]);void lcong48(unsigned shortparam[7]);   Feature Test Macro Requirements for glibc (seefeature_test_macros(7)):       All functions shown above:           _XOPEN_SOURCE               || /* glibc >= 2.19: */ _DEFAULT_SOURCE               || /* glibc <= 2.19: */ _SVID_SOURCE

DESCRIPTION        top

       These functions generate pseudo-random numbers using the linear       congruential algorithm and 48-bit integer arithmetic.       Thedrand48() anderand48() functions return nonnegative double-       precision floating-point values uniformly distributed over the       interval [0.0, 1.0).       Thelrand48() andnrand48() functions return nonnegative long       integers uniformly distributed over the interval [0, 2^31).       Themrand48() andjrand48() functions return signed long integers       uniformly distributed over the interval [-2^31, 2^31).       Thesrand48(),seed48(), andlcong48() functions are       initialization functions, one of which should be called before       usingdrand48(),lrand48(), ormrand48().  The functionserand48(),nrand48(), andjrand48() do not require an       initialization function to be called first.       All the functions work by generating a sequence of 48-bit       integers,Xi, according to the linear congruential formula:Xn+1 = (aXn + c) mod m, where n >= 0       The parameterm = 2^48, hence 48-bit integer arithmetic is       performed.  Unlesslcong48() is called,a andc are given by:a = 0x5DEECE66Dc = 0xB       The value returned by any of the functionsdrand48(),erand48(),lrand48(),nrand48(),mrand48(), orjrand48() is computed by first       generating the next 48-bitXi in the sequence.  Then the       appropriate number of bits, according to the type of data item to       be returned, is copied from the high-order bits ofXi and       transformed into the returned value.       The functionsdrand48(),lrand48(), andmrand48() store the last       48-bitXi generated in an internal buffer.  The functionserand48(),nrand48(), andjrand48() require the calling program to       provide storage for the successiveXi values in the array argumentxsubi.  The functions are initialized by placing the initial value       ofXi into the array before calling the function for the first       time.       The initializer functionsrand48() sets the high order 32-bits ofXi to the argumentseedval.  The low order 16-bits are set to the       arbitrary value 0x330E.       The initializer functionseed48() sets the value ofXi to the       48-bit value specified in the array argumentseed16v.  The       previous value ofXi is copied into an internal buffer and a       pointer to this buffer is returned byseed48().       The initialization functionlcong48() allows the user to specify       initial values forXi,a, andc.  Array argument elementsparam[0-2] specifyXi,param[3-5] specifya, andparam[6]       specifiesc.  Afterlcong48() has been called, a subsequent call       to eithersrand48() orseed48() will restore the standard values       ofa andc.

ATTRIBUTES        top

       For an explanation of the terms used in this section, seeattributes(7).       ┌─────────────────────────────────┬───────────────┬──────────────┐       │InterfaceAttributeValue│       ├─────────────────────────────────┼───────────────┼──────────────┤       │drand48(),erand48(),           │ Thread safety │ MT-Unsafe    │       │lrand48(),nrand48(),           │               │ race:drand48 │       │mrand48(),jrand48(),           │               │              │       │srand48(),seed48(),lcong48()  │               │              │       └─────────────────────────────────┴───────────────┴──────────────┘       The above functions record global state information for the random       number generator, so they are not thread-safe.

STANDARDS        top

       POSIX.1-2008.

HISTORY        top

       POSIX.1-2001, SVr4.

SEE ALSO        top

rand(3),random(3)

COLOPHON        top

       This page is part of theman-pages (Linux kernel and C library       user-space interface documentation) project.  Information about       the project can be found at        ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report       for this manual page, see       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.       This page was obtained from the tarball man-pages-6.15.tar.gz       fetched from       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on       2025-08-11.  If you discover any rendering problems in this HTML       version of the page, or you believe there is a better or more up-       to-date source for the page, or you have corrections or       improvements to the information in this COLOPHON (which isnot       part of the original manual page), send a mail to       man-pages@man7.orgLinux man-pages 6.15            2025-05-17drand48(3)

Pages that refer to this page:arc4random(3)drand48_r(3)rand(3)random(3)random_r(3)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp