我希望能够从我将要放置的特定数组中生成随机数.例如:我想从数组{2,6,4,8,5}生成一个随机数.它只是我想要生成的数组中没有模式.
我只能使用视频教程https://www.youtube.com/watch?v=P7kCXepUbZ0&list=PL9156F5253BE624A5&index=16中的 srand()搜索如何从1-100生成随机数,但我不知道如何指定它将搜索的数组..
顺便说一句,我的代码与此相似..
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(int argc, char*argv[])
{
srand(time(0));
int i =rand()%100+1;
cout << i << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)