Answers for "rng using Random in java"

9

how to generate a random number in java

import java.util.Random;

Random rand = new Random();
int maxNumber = 10;

int randomNumber = rand.nextInt(maxNumber) + 1;

System.out.println(randomNumber);
Posted by: Guest on August-18-2020
0

Java random number generator

Random random = new Random();
long v1 = random.nextInt();
long v2 = random.nextInt();
for (int i = 0; i < 65536; i++) {
    long seed = v1 * 65536 + i;
    if (((seed * multiplier + addend) & mask) >>> 16) == v2) {
        System.out.println("Seed found: " + seed);
        break;
    }
}
Posted by: Guest on October-16-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language