double d = Math.random(); double x = d*6.0; while (x < 1) { x = x + Math.random(); } System.out.println(x);