问题描述
- 求怎么输出多个伪随机数
-
int a[1000];
for(int b=0;b<1000;++b)
{
srand((int)time(0));
}
for(int j=0;j<1000;j++)
{a[b]=rand();
}
我写的是上面的,总是报错,不知道哪里错了,跪求大神啊
解决方案
srand调用1次就行
错误在于 a[b] 总下标 b 已经超出定义的作用范围。
int a[1000];
srand((int)time(0));
for(int j=0;j<1000;j++)
{
a[j]=rand();
}
解决方案二:
http://zgjmail1017.blog.163.com/blog/static/1218567702011527271620/
时间: 2024-08-02 17:38:26