素描画树:如何在VC++中随机产生一个数字?

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/26 04:24:30

MSDN的example

// crt_rand.c
/* This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/

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

int main( void )
{
int i;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );

/* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}