Given a series of numbers generated by rand(), how can I predict the next value? Brute force is out of the question. I'm aware that rand() is basically a linear congruential generator, but also makes bit shifting. What theory can I use to crack it? Any hints will be most welcome :)
-
I read somewhere (Wikipedia???) you need 650 (?) results to identify the PRNG sequence and where you are in it. You might like the Wikipedia article "Random number generator attack".– pmgCommented Mar 18, 2013 at 16:03
-
It's perhaps a spoiler, but you can of course start by reading the code to get an understanding of what to expect ...– unwindCommented Mar 18, 2013 at 16:04
-
1Iirc glibs uses a simple LCG for rand_r() and aliases rand()/random() together ==> try rand_r().– lorebCommented Mar 18, 2013 at 16:44
-
1If you are on the same system as the one that generates your sequence, you could set as seed the latest number with srand() and "predict" the next one with rand().– anumiCommented Mar 18, 2013 at 19:20
Add a comment
|
1 Answer
@unwind: thanks for the advice! I was wrong in some places, and the documentation got me on the right track.
Actually, predicting is a piece of cake when you know a sequence of 30 (or so) numbers. The 'computed' answer will be right in 50% of cases. More details present in the link provided by unwind, or in a simplified code: http://www.mathstat.dal.ca/~selinger/random/
-
I meant to answer it. The strict, accurate answer is really obvious after just looking at the code. Instead of giving a straightforward reply, I decided to leave a helpful link. The problem literally solves itself after a short lecture :) Commented Mar 19, 2013 at 18:02