#include <stdlib.h>
#include <time.h>
int getRand(int begin,int end)
{
srand((unsigned)time(NULL));
return rand()%(end - begin + 1) + begin;
}
C++,取得[a,b]的随机整数,使用(rand()%(b-a+1)+a);
最新推荐文章于 2025-03-19 22:28:55 发布
#include <stdlib.h>
#include <time.h>
int getRand(int begin,int end)
{
srand((unsigned)time(NULL));
return rand()%(end - begin + 1) + begin;
}