打开微信消息的快捷键:在vc++中什么函数具有随机产生数字的功能 ?

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 19:30:42
在matlab中的rand 就有随机产生数据的功能,在c++中是不是也有同样功能的函数

你可以这样做
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

void 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() );
}

rand()函数就可以了
如果要生成0~99的随机数可以:rand()%100