import java.util.Random;
Random rand = new Random();
// Obtain a number between [0 - 49].
int n = rand.nextInt(50);
// Add 1 to the result to get a number from the required range
// (i.e., [1 - 50]).
n += 1;
import java.util.Random;
class scratch{
public static void main(String[] args) {
Random rand = new Random();
System.out.println( rand.nextInt(5) );
//prints a random Int between 0 - 4 (including 0 & 4);
}
}
double x = (Math.random()*((max-min)+1))+min;
int random = (int) (Math.random()*(max-min+1)+min);
Min + (int)(Math.random() * ((Max - Min) + 1))
import java.util.Random;
Random rand = new Random();
// Obtain a number between [0 - 49].
int n = rand.nextInt(50);
// Add 1 to the result to get a number from the required range
// (i.e., [1 - 50]).
n += 1;
import java.util.Random;
Random rand = new Random();
// You can also provide bound to it
rand.nextInt();
class GenerateRandom {
public static void main( String args[] ) {
int min = 50;
int max = 100;
//Generate random int value from 50 to 100
System.out.println("Random value in int from "+min+" to "+max+ ":");
int random_int = (int)Math.floor(Math.random()*(max-min+1)+min);
System.out.println(random_int);
}
}
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;
}
}