create a random sequence, skip to any part of the sequence

Posted by Michael Xu on Stack Overflow See other posts from Stack Overflow or by Michael Xu
Published on 2010-05-04T21:41:28Z Indexed on 2010/05/04 21:48 UTC
Read the original article Hit count: 482

Filed under:
|

Hi everyone,

In Linux. There is an srand() function, where you supply a seed and it will guarantee the same sequence of pseudorandom numbers in subsequent calls to the random() function afterwards.

Lets say, I want to store this pseudo random sequence by remembering this seed value.

Furthermore, let's say I want the 100 thousandth number in this pseudo random sequence later.

One way, would be to supply the seed number using srand(), and then calling random() 100 thousand times, and remembering this number.

Is there a better way of skipping all 99,999 other numbers in the pseudo random list and directly getting the 100 thousandth number in the list.

thanks,

m

© Stack Overflow or respective owner

Related posts about random

Related posts about srand