Jump to content
  • Advertisement
Sign in to follow this  
godmodder

Calculating seed from random numbers

This topic is 3714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I was just wondering: given a set of random numbers, would it be possible to calculate the random seed that was used to generate them? Suppose I have this serie of numbers between 0 and 10: "5, 1, 6, 8, 4" and I know that the rand() function (or some other algorithm) was used to generate them. Is it possible to know what seed was used from the numbers it generates? I don't know much about random number algorithms, so don't laugh when this sounds absolutely crazy ;) Jeroen

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by godmodder
I was just wondering: given a set of random numbers, would it be possible to calculate the random seed that was used to generate them?


Yes, this is possible for any random number generator with a finite number of states, given that your sequence is big enough. Simply test all possible seeds and select the one which works.

Of course, this will take a long time if the algorithm is cryptographically secure. For classic unsafe generators such as LCG or Mersenne, you should be able to deduce the seed in polynomial time.

Quote:
the rand() function (or some other algorithm) was used to generate them.


The rand() function is not an algorithm. However, every platform will use an algorithm (possibly a different one) to implement it.


Share this post


Link to post
Share on other sites
An easy way is to pre-calculate a dictionary of first few elements of a every possible sequence, then match your input against that. Since rand is quite fast, this might not bring any benefits, unless some property exists that could be used in the dictionary.

Depending on the algorithm, you might not be able to recover exact seed, only one that generates same N elements.

The reasoning behind this comes from information theory. n-bit seed can only define 2^n unique sequences. This is also the reason why checksum collision occur, and why they can be, in many cases, trivially exploited.

For seeds larger than 32 bits, it may not be viable without some degree of algorithmic optimization.

One problem however is that for many algorithms, every member of sequence is used as seed for next one. As such, finding the original seed might be impossible.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!