random Java import code example

Example 1: 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);

Example 2: generate random number in java

import java.lang.Math;

int randomNumber;

int minimum = 1;
int maximum = 10 - minimum;

randomNumber = (int)((Math.random()*maximum) + minimum);

System.out.println("Random Number (Between 1-10): " + randomNumber);

Example 3: random java

import java.util.Random();
Random <name> = new Random();
<variable> = <name>.nextInt(<excuslive top limit>);

Example 4: java random

String id = UUID.randomUUID().toString();