请问,vc++中随机函数如何调用(200分)

  • 主题发起人 主题发起人 lhlh_0_0
  • 开始时间 开始时间
L

lhlh_0_0

Unregistered / Unconfirmed
GUEST, unregistred user!
我在vc++中参考c语言调用随机函数,结果说randomize未定义,请求高手
{#include <stdlib.h>
#include <stdio.h>
void main()
{Randomize();}
D:/my work/random/random.cpp(6) : error C2065: 'Randomize' : undeclared identifier
无论是randomize还是Randomize都不行
 
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;
i<10;
i++)
printf("%d", rand());
return 0;
}
 
根本就没有Randomize函数,应该用rand()函数.
Example
/* 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>
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() );
}

Output
6929
8026
21987
30734
20587
6699
22034
25051
7988
10104
 
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=0;
i<10;
i++)
printf("%d", rand()%100);//100指你所需要的范围
return 0;
}
 
我觉得VC中的随机函数不能作为C语言的随机函数参考。
反正我觉得tc和vc的随机函数很不一样。
正如huxiaoxuan所写,VC调用rand,要先srand( (unsigned)time( NULL ) );取得随机函数的种子。

tc下,您要参考,则光标钉在rand上,按ctrl+F1
 
多人接受答案了。
 
后退
顶部