mardi 30 mai 2017

Getting base seed for pRNG given an array of data

I was wondering if, given a known PRNG and a set of values, one could calculate that PRNG's base seed. For example, say I have an array of data

var a = [255, 192, 0, 3, 72]

I know for a fact that each of those values was generated from calls PRNG.nextInt(). So the first call to PRNG.nextInt() returned 255, the next call returned 192, and so on. If you were only given that data set, is there a PRNG algorithm to give me the original seed? So that you could do something like this:

var seed = PRNG.getSeedForData([255, 192, 0, 3, 72])
var prng = new PRNG(seed)

And then with that prng instance, this should be true:

prng.nextInt() == 255
prng.nextInt() == 192
prng.nextInt() == 0
prng.nextInt() == 3
prnt.nextInt() == 72

I looked at this post (Is it possible to reverse a pseudo random number generator?) as well as this one (Given a RNG algorithm and a series of numbers is it possible to determine what seed would produce the series?), but I'm not sure what to do with that information. It doesn't look like either post found a solution to the problem, however, and I don't want to necropost.

Based on what little I understood from those posts, though, it looks like Linear congruential generators might be the way to go?, but I'm not entirely sure how to even approach them.


Just to clarify, I trying to write an PRNG algorithm that can also give me a seed when supplied with a series of numbers. The nextInt() function in the algorithm should ideally always return a value between 0 and 255, but I'm not sure if that is relevant to the question.




Aucun commentaire:

Enregistrer un commentaire