auto n[]={"\xda\x01\x09\xfc\xca\x98\x82\x33\x69\xaa\xc1\xdf\xbb\x40\x90\xcf",
"\xda\x01\x09\xfc\xca\x98\x82\x33\x69\xaa\xc1\xdf\xbb\x40\x90\xcf",};
auto key=nullptr;
jstring
randomKey(jstring n[] )
{
//生成隨機數
srand((unsigned)time((long *)0));
int nlen=rand()%(sizeof(n)/sizeof(n[0]));
return n[nlen];
}
我定義一個 數組,想隨機取出來數組中的值,然後賦值給一個變量,我該怎麼寫呢,剛接觸C不懂,求解決
#include <iostream>
#include <time.h>
using namespace std;
char randomKey(string n[])
{
srand(time(NULL));
int nlen = rand() % n[0].length();
return n[0][nlen];
}
int main()
{
string n[] = { "\xda\x01\x09\xfc\xca\x98\x82\x33\x69\xaa\xc1\xdf\xbb\x40\x90\xcf",
"\xda\x01\x09\xfc\xca\x98\x82\x33\x69\xaa\xc1\xdf\xbb\x40\x90\xcf" };
cout << randomKey(n);
}
C++經典寫法