Android Question Backward Seed?

Quillok

Member
Licensed User
Hey,
actually I'm thinking about if it is possible to use random and seed to generate a large number.

Let me explain:
I've got the number 123456789
Now I want to get the exact number on another device using the seed possibility.
Would it be possible to "create" a seed that would definitely throw this number when using rnd(0,999999999)?
 

emexes

Well-Known Member
Licensed User
The pseudorandom sequence is something like:

new_state = (old_state * C1 + C2) modulo N

where C1 and N are probably prime, or at least prime relative to each other, so that the sequence would travel through every possibility before repeating. Presumably nowadays the randomizing function is more complicated.

I also remember a story about people cracking an online poker site because they worked out the random number generator sequence and thus had a good idea of which cards the other players were likely to have. The headline had me thinking it was a made-up story, but when digging into it a bit deeper, it actually seemed plausible.

Anyway, I am off to dump a few random numbers, see how we go. 16-bit sequences would be no problem, 32-bit would be doable with effort, 64-bit would be... interesting.
 
Last edited:

emexes

Well-Known Member
Licensed User
Try:
B4X:
RndSeed(12288128)
Log(Rnd(0, 999999999))

RndSeed(101501290)
Log(Rnd(0, 999999999))

RndSeed(592276329)
Log(Rnd(0, 999999999))
I am mildly worried that there are three 9-digit seeds that produce the same 9-digit random number - this makes me think that there exist some 9-digit random numbers that don't have a 9-digit seed. Hmm. Although probably there is a 10 or 11 digit seed that will do the job.

Anyway, the other minor issue is that the documentation for Rnd() says:

upload_2019-8-28_1-57-43.png


ie Rnd(0, 999999999) will never return 999999999 (per "Max (exclusive)") and thus it would be better to use Rnd(0, 1000000000) eg:
B4X:
RndSeed(12288128)
Log(Rnd(0, 1000000000))

RndSeed(592276329)
Log(Rnd(0, 1000000000))
 

emexes

Well-Known Member
Licensed User
Top