Share via


rand (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Generates a pseudorandom number.

int rand(    void );

Return Values

rand returns a pseudorandom number, as described above.

There is no error return.

Remarks

The rand function returns a pseudorandom integer in the range 0 to RAND_MAX.

Use the srand function to seed the pseudorandom-number generator before calling rand.

Example

/* RAND.C: This program seeds the random-number generator
* with the GetTickCount, then displays 10 random integers.
 */

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

void main( void )
{
   int i;
   /* Seed the random-number generator with GetTickCount so that
      the numbers will be different every time we run.
       */
   srand(
       GetTickCount() 
         );
   /* Display 10 numbers. */
   for(
         i = 0;   i < 10;i++ 
        )
   printf(
         "%6d\n", rand() 
        );
   }

Requirements

OS Versions: Windows CE 2.0 and later.
Header: stdlib.h.
Link Library: coredll.dll.

See Also

srand

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.