看了一下msdn的用法/* 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 如果象他这样用的话,即使和100取模,也没有什么规律性阿
所以产生的数据还是有规律的~~~
一个比较笨的方法是你可以在每次产生的数据后面加一句Sleep(1000);
这样你看看效果~~~
大概是这个函数,搂主人试试
rand_s(unsigned int* randomValue)
* 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
如果象他这样用的话,即使和100取模,也没有什么规律性阿
因此如果多次调用rand()之间没有控制时间的语句,产生的随机数序列肯定是有规律的(sleep(1000)应该也不行)
在每次rand之后加一句getch(),应该是可以打破这种规律的