Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
rand(3C)							      rand(3C)

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

SYNOPSIS
DESCRIPTION
       uses  a	multiplicative,	congruential, random-number generator with pe-
       riod 2^32 that returns successive pseudo-random numbers	in  the	 range
       from 0 to 2^15-1.

       can  be	called	at  any	time to	reset the random-number	generator to a
       random starting point.  The generator is	initially seeded with a	 value
       of 1.

       returns a random	number at the address pointed to by the	randval	param-
       eter.  The seed parameter can be	set at any time	to start  the  random-
       number generator	at an arbitrary	point.

RETURN VALUE
       If  seed	 or  randval is	NULL, returns 0.  Otherwise, returns a psuedo-
       random integer.

EXAMPLE
       The following:

	      int x, y;
	      srand(10);
	      x	= rand();
	      y	= rand();

       would produce the same results as:

	      int x, y,	s = 10;
	      x=rand_r(&s);
	      y=rand_r(&s);

NOTE
       The spectral properties of leave	a great	deal to	be desired.   provides
       a  much	better,	 though	 more  elaborate, random-number	generator (see
       drand48(3C)).

WARNINGS
       Users of	should note that rand_r() now conforms with POSIX.1c.  The old
       prototype  of is	supported for compatibility with existing DCE applica-
       tions only.

SEE ALSO
       drand48(3C), random(3M),	thread_safety(5).

STANDARDS CONFORMANCE
								      rand(3C)

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | EXAMPLE | NOTE | WARNINGS | SEE ALSO | STANDARDS CONFORMANCE

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=rand&sektion=3c&manpath=HP-UX+11.22>

home | help