Borland C++ reference

rand

raw OCR

Random number generator.

Defined in header <stdlib.h>

Syntax

#include <stdlib.h>
int rand(void);

Portability

DOSUNIXWindowsANSI CC++ only
■■■■

Remarks

rand uses a multiplicative congruential random number generator with period Tp- to return successive pseudorandom numbers in the range from

0 to RAND_MAX.The symboHc constant RAND_MAXis defined in

stdlib.h; its value is 2^^ - 1.

Return value

rand returns the generated pseudorandom number.

See also

Example

itinclude <stdlib.h>
#include <stdio.h>

int main(void)
{
   int i;
   printfC'Ten random numbers  from 0 to 99\n\n");
   for(i=0; i<10; i++)
      printf ("%d\n", randO  % 100);
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.