C++ 在c+中生成随机数+;语言 #包括 #包括 int随机[1000]; 使用名称空间std; char*getDateTime(time\u t&x); 短getGeneratedNumber(时间和日期时间); int main() { 现在的时间=0; char*timeString; int i=0; timeString=getDateTime(现在); 对于(int j=1;j
第一,您的循环是错误的(请记住,在C++中,与MATLAB相反,索引从0开始):C++ 在c+中生成随机数+;语言 #包括 #包括 int随机[1000]; 使用名称空间std; char*getDateTime(time\u t&x); 短getGeneratedNumber(时间和日期时间); int main() { 现在的时间=0; char*timeString; int i=0; timeString=getDateTime(现在); 对于(int j=1;j,c++,C++,第一,您的循环是错误的(请记住,在C++中,与MATLAB相反,索引从0开始): 用于(int j=1;j并不是说你应该首先做这件事,而是问问你在程序的过程中调用了多少次代码< GETDATECTIME/。实际上,计算它们不会花费很长时间。然后,停止使用时间,开始使用。这是在现代C++中非加密强度随机数的晚餐。程序 #include<iostream> #include <ctime> int random[1000]; using namespace std; c
用于(int j=1;j并不是说你应该首先做这件事,而是问问你在程序的过程中调用了多少次代码< GETDATECTIME/<代码>。实际上,计算它们不会花费很长时间。然后,停止使用<代码>时间<代码>,开始使用。这是在现代C++中非加密强度随机数的晚餐。程序
#include<iostream>
#include <ctime>
int random[1000];
using namespace std;
char* getDateTime(time_t &x);
short getGeneratedNumber(time_t &dateTime);
int main()
{
time_t now = 0;
char* timeString;
int i = 0;
timeString = getDateTime(now);
for (int j = 1; j <= 1000; j++) {
random[j] = getGeneratedNumber(now);
cout << random[j] << " ";
}
}
char* getDateTime(time_t &x) {
// current date/time based on current system
x = time(0); // updates the value of the variable now
// convert now to string form
char* dt = ctime(&x);
return dt;
}
short getGeneratedNumber(time_t &x) {
return x % 1000;
}
for (int j = 1; j <= 1000; j++)
for (int j = 0; j < 1000; j++)