rand(3c) 맨 페이지 - 윈디하나의 솔라나라

개요

섹션
맨 페이지 이름
검색(S)

rand(3c)

Standard C Library Functions                                          rand(3C)



NAME
       rand, srand, rand_r - simple random-number generator

SYNOPSIS
       #include <stdlib.h>

       int rand(void);


       void srand(unsigned int seed);


       int rand_r(unsigned int *seed);

DESCRIPTION
       The  rand()  function  uses a multiplicative congruential random-number
       generator with period 2^32 that returns successive  pseudo-random  num‐
       bers in the range of 0 to RAND_MAX (defined in <stdlib.h>).


       The  srand()  function  uses  the  argument  seed  as  a seed for a new
       sequence of pseudo-random numbers to be returned by subsequent calls to
       rand().  If  srand()  is  then  called  with  the  same seed value, the
       sequence of pseudo-random numbers will be repeated. If rand() is called
       before  any  calls to srand() have been made, the same sequence will be
       generated as when srand() is first called with a seed value of 1.


       The rand_r() function has the same functionality as rand() except  that
       a pointer to a seed seed must be supplied by the caller. If rand_r() is
       called with the same initial value for the object pointed  to  by  seed
       and  that  object is not modified between successive calls to rand_r(),
       the same sequence as that produced by calls to rand()  will  be  gener‐
       ated.


       The  rand()  and  srand()  functions  provide per-process pseudo-random
       streams shared by all threads. The same effect can be achieved  if  all
       threads  call  rand_r()  with  a  pointer  to the same seed object. The
       rand_r() function allows a thread to generate a  private  pseudo-random
       stream by having the seed object be private to the thread.

USAGE
       The spectral properties of rand() are limited. The drand48(3C) function
       provides a better, more elaborate random-number generator.


       Programmers should use /dev/urandom or /dev/random for most random-num‐
       ber generation, especially for cryptographic purposes. See random(4D).

ATTRIBUTES
       See attributes(7) for descriptions of the following attributes:


       tab()  box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) ATTRIBUTE TYPEAT‐
       TRIBUTE VALUE _ Interface StabilityCommitted _ MT-LevelSafe _ Standard‐
       See standards(7).


SEE ALSO
       drand48(3C), random(4D), attributes(7), standards(7)



Oracle Solaris 11.4               16 May 2014                         rand(3C)
맨 페이지 내용의 저작권은 맨 페이지 작성자에게 있습니다.
RSS ATOM XHTML 5 CSS3