大随机数的生成

jqx_ah 2008-06-27 01:38:55
for(int i=0;i<32;i++)
{
srand(time(NULL));
a[i]=rand()%+1;
}
结果 却不随机
值完全一样
a是unsigned long 型

如何解决阿
...全文
147 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bychahaha 2011-11-20
  • 打赏
  • 举报
回复
re!
[Quote=引用 3 楼 bellbird 的回复:]

大随机数,被标题给忽悠了
[/Quote]
jqx_ah 2008-06-27
  • 打赏
  • 举报
回复
恩 我的就是这样实现的

不过 随机还是不够 好!

我的是 32位一个进制!
jqx_ah 2008-06-27
  • 打赏
  • 举报
回复
用你的方法 作了一下
连续4到5个是还是一样的数字
还是不能随机的很好!
jsjjms 2008-06-27
  • 打赏
  • 举报
回复
产生随机数,需要一个“种子”,一般以当前机器时间为种子。

但如果大随机数,就比较复杂了。

(给点小建议: 我们用16进制可以表示0~15,那么如果用1024进制,是否可以表示0~1023呢? 依次类推,可以在一定

程度上产生大随机数)
bellbird 2008-06-27
  • 打赏
  • 举报
回复
大随机数,被标题给忽悠了
OutIT人 2008-06-27
  • 打赏
  • 举报
回复
#include<iostream>   
#include<iomanip>
#include<ctime>
#include<cstdlib>

using namespace std;

const int N=20;

int main()
{
srand(time(NULL));
int i;
int a[N];

for(i=0;i<N;++i)
{
a[i]=rand()%100;
cout<<setw(5)<<a[i];
}
cout<<endl;

system("pause");
return 0;
}
OutIT人 2008-06-27
  • 打赏
  • 举报
回复
 #include   <stdlib.h>   
#include <stdio.h>
#include <time.h>

void main( void )
{
int i;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );

/* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧