5

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 :)

4
  • 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".
    – pmg
    Commented 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 ...
    – unwind
    Commented Mar 18, 2013 at 16:04
  • 1
    Iirc glibs uses a simple LCG for rand_r() and aliases rand()/random() together ==> try rand_r().
    – loreb
    Commented Mar 18, 2013 at 16:44
  • 1
    If 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().
    – anumi
    Commented Mar 18, 2013 at 19:20

1 Answer 1

5

@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/

1
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.