#include <stdlib.h>
#include <time.h>
#define X_RANDOM(a,b) (rand()%((b)-(a)) + (a))
static int xrange_rand(int a, int b)
{
//srand( (unsigned)time(NULL) );
int rd = (rand()%((b)-(a)) + (a));
return rd;
#include <time.h>
#define X_RANDOM(a,b) (rand()%((b)-(a)) + (a))
static int xrange_rand(int a, int b)
{
//srand( (unsigned)time(NULL) );
int rd = (rand()%((b)-(a)) + (a));
return rd;
}
///用以上方便可以生成指定范围的随机数,比如1-10000,在某些场合下会有这样的需要。
这里有一点要提一下,加入代码 srand( (unsigned)time(NULL) ); 那么,如果要在一秒内要生成很多个随机数,将会生成一样的数据。所以要去掉这行代码。
886

被折叠的 条评论
为什么被折叠?



