다음을 통해 공유


srand (Windows CE 5.0)

Send Feedback

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

Sets a random starting point.

void srand( unsigned intseed);

Parameters

  • seed
    Seed for random-number generation.

Return Values

None.

Remarks

These functions are supported by all versions of the C run-time libraries.

The srand function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point.

rand retrieves the pseudorandom numbers that are generated. Calling rand before any call to srand generates the same sequence as calling srand with seed passed as 1.

Example

Description

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

Code

#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

rand

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.