Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>rand() get pseudorandom integer</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
rand()                   Get Pseudorandom Integer

 #include   <stdlib.h>                   Required for declarations only

 int        rand(void);

    rand() returns a pseudorandom integer in the range 0-32767. srand()
    can be used before calling rand() to set a random starting point.

    Returns:    A pseudorandom number in the range 0 to 32767 (maximum
                integer size).  There is no error return.

  -------------------------------- Example ---------------------------------

    The following statements generate 10 random numbers in the range 0 to
    32767 and print them out.

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

          int i;

          main()
          {
               printf("     RANDOM NUMBERS \n");
               for (i = 1; i <= 10; i++)
                   printf("index: %d,  random number: %d \n",i,rand());
           }

See Also: srand()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson