Home > database >  Are there any java.util.random seeds with bad/weird properties?
Are there any java.util.random seeds with bad/weird properties?

Time:08-05

I'm curious if there are seeds for java.util.random which have weird/surprising properties. This has little practical use, but I'm still curious.

edit: by weird/surprising properties I mean repeating values or atypical patterns.

CodePudding user response:

Yes!

The java.util.Random object's constructor takes in a long as an argument. A bit of sifting through internal classes, we find that this long is processed through the following function:

private static long initialScramble(long seed) {
    return (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1);
}

The goal of this function is to scramble the seed enough so the resulting seed is uniformly distributed across the long range (or something like that).

All we have to do is find an input to this function where it will produce an output of 0 to break things

  • Related