I know math.random()
in javascript can be predicted if you know the exact outputs of it, but if I only know what it gives after doing math.floor(100 / (1.0001 - Math.random()))
, how would I use this to predict the next number?
1 Answer
To predict the next number generated by Math.random()
in JavaScript, given the outputs after applying Math.floor(100 / (1.0001 - Math.random()))
, follow these steps:
Understand the transformation and solve for the possible values of
Math.random()
before the transformation. This gives you a range for each observed output.Narrow down the possible values for
Math.random()
by intersecting the ranges obtained from multiple outputs. This helps in approximating the internal state of the pseudo-random number generator (PRNG).Model the PRNG's state by using the observed outputs to backtrack to the possible internal states or seeds of the PRNG.
Predict future values by simulating the PRNG algorithm from the inferred state. This requires knowledge of the PRNG algorithm used by JavaScript.
By following these steps, you can incrementally limit the possible states of the PRNG until you have a precise model that allows you to predict the next number generated by Math.random()
.
Maybe this related question and especially the linked github repo can help you to understand how to implement such a tool.
-
I saw that but I don't know the z3 solver so I don't know how to adapt it to my situation or if it's even possible. Commented Aug 5 at 15:45