Skip to content

Math.random

Sharina Stubbs edited this page Jan 7, 2020 · 1 revision

math.Random returns a double, per the docs. Check out docs.oracle.com on Math.

double rand = Math.random();
int year = (int) Math.ceil(rand * 2020);
System.out.println(String.format("The year is %d.", year));
if(isLucky(year)) {
  System.out.println("so lucky!");
} else {
  System.out.println("try again!");
Clone this wiki locally