函数定义
int randBetween(int numL, int numH) { int a; double b; int c;
if (numL > numH) //交换 { int tmp; tmp = numH; numH = numL; numL = tmp; }
do { a = rand(); //产生0到RAND_MAX之间的随机数 b = a / sqrt(a + 1); c = (int)b; if (numL <= c && c <= numH) { return c; } } while(1); }
函数调用
void Hello()
{
int nRan = randBetween(10, 20); ads_printf("\n 随机数= %d", nRan);
} |