How to generate random numbers in Java

Random integer up to Max

import java.util.Random;

public static int generateRandomInteger(int max) {
    Random random = new Random();
    return random.nextInt(max);
}

Random integer between Min and Max

import java.util.Random;

public static int generateRandomNumber(int min, int max) {
    Random random = new Random();
    return random.nextInt(max - min + 1) + min;
}

Random float up to Max

import java.util.Random;

public static float generateRandomFloat(float max) {
    Random random = new Random();
    return random.nextFloat() * max;
}

Random float between 0 and 1

// random float between 0 and 1
Random random = new Random();
float randomFloat = random.nextFloat();