如何找到随机无生成器生成的整数数组的种子 [英] How to find seed of an integer array generated by random no generator

查看:80
本文介绍了如何找到随机无生成器生成的整数数组的种子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下函数生成随机数组,当我设置种子

 srand( 0 

此程序每次生成完全相同的整数数组,即

  38   39   118   5   23   21   45   29  

现在我想通过引用相同的数组来了解srand()的种子。



我尝试了什么:



i使用这些代码生成数组

  #include  < span class =code-preprocessor> <   iostream   >  
#include < conio.h >
#include < stdlib.h >
#include < time.h >
使用 命名空间标准;
int main( void ){
int i;
srand( 0 );
for (i = 0 ; i< 8; i ++)
{
int x = rand()%128; // 0到128之间
cout<< x<< ;
}
}

解决方案

算了吧。这根本不实用。种子值是一个无符号整数 - 这意味着这些天是32位数 - 所以你有一个可能需要检查查找的2 ^ 32个不同的数组组合:4,294,967,296个可能的值。而主要的问题是,这些中的大量数据是相同的 - 或者至少从相同的开始 - 你可能需要获得大量的随机数元素然后才能消除它们中的一部分。



这对任何事情都不实用。我知道:很多年前,当我刚刚开始时,我试图将它用作超级压缩技术,当我意识到需要多长时间才能尝试找到随机数字序列生成我想要压缩的字节流! :笑:

I used following function to generate array of random numbers ,when i set seed

srand(0)

this program generate exact same array of integers every time, i.e.

38 39 118 5 23 21 45 29

Now i want to know seed of srand() by feding same array.

What I have tried:

i used these codes to generate array

#include<iostream>
#include<conio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(void) {
	int i;
    srand(0);
     for (i=0; i<8;i++)
	{
        int x = rand()%128;     //between 0 and 128
        cout<<x<<" ";
    }
}

解决方案

Forget it. It's not at all practical. The seed value is an unsigned integer - which means a 32 bit number these days - so you have a possible 2^32 different array combinations you would need to "check back" to find: 4,294,967,296 possible values. And the main problem is that there are going to be a huge number of these that are the same - or at least start off the same - and you may need to get to a significant number of random number elements before you can eliminate some of them.

This is not a practical approach to anything. I know: I tried to use it as a "super compression" technique many, many years ago when I was just starting and eventually gave up when I realised just how long it was going to take to try and find a random number sequence that "generated" the byte stream I wanted to compress! :laugh:


这篇关于如何找到随机无生成器生成的整数数组的种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆