Skip to content

Instantly share code, notes, and snippets.

@mizdra
Created April 2, 2016 16:04
Show Gist options
  • Save mizdra/539977433c4e5b551dce7c4a8e0072e1 to your computer and use it in GitHub Desktop.
Save mizdra/539977433c4e5b551dce7c4a8e0072e1 to your computer and use it in GitHub Desktop.
public class Main {
public static final int MULTIPLIER = 0x41c64e6d;
public static final int INCREMENT = 0x6073;
public static void main(String[] args){
System.out.println("MULTIPLIER: 0x" + Integer.toHexString(MULTIPLIER));
System.out.println("INCREMENT: 0x" + Integer.toHexString(INCREMENT));
int multiplierInverse = 0x00000000;
// multiplierInverseを0x00000000~0xFFFFFFFFまで総当り
while(true){
int result = MULTIPLIER * multiplierInverse;
// MULTIPLIER * multiplierInverse == 1のとき、multiplierInverseが逆向きLCGのmultiplierである
if(result == 1){
int incrementInverse = (int)(0x100000000L - INCREMENT) * multiplierInverse;
System.out.println("multiplierInverse: 0x" + Integer.toHexString(multiplierInverse));
System.out.println("incrementInverse: 0x" + Integer.toHexString(incrementInverse));
}
if(multiplierInverse == 0xFFFFFFFF)
break;
multiplierInverse++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment