Inverse function of Java's Random function

后端 未结 3 1831
走了就别回头了
走了就别回头了 2020-12-08 14:34

Java\'s Random function takes a seed and produces the a sequence of \'psuedo-random\' numbers. (It is implemented based on some algorithm discussed in Donald Knuth, Th

3条回答
  •  佛祖请我去吃肉
    2020-12-08 15:34

    I normally wouldn't just link articles... But I found a site where someone looks into this in some depth and thought it was worth posting. http://jazzy.id.au/default/2010/09/20/cracking_random_number_generators_part_1.html

    It seems that you can calculate a seed this way:

    seed = (seed * multiplier + addend) mod (2 ^ precision)
    

    where multiplier is 25214903917, addend is 11, and precision is 48 (bits). You can't calculate what the seed was with only 1 number, but you can with 2.

    EDIT: As nhahtdh said there's a part 2 where he delves into more of the math behind the seeds.

提交回复
热议问题