Math: random()
/* * Output: 0.2582865756128041 0.9294301072371337 1.0920958792665798 1.4810070289722757 1.8399471246981638 2.781546148684157 3.5957542851066675 4.113758777037293 4.150439043318967 4.529427701584921 5.512453021311045 6.251471026501456 6.905859639865632 7.2068223631146955 7.921371780218516 8.557002165650722 9.478668455875274 9.595839446980102 9.647163478750608 9.668347992354768 9.683406705822547 10.598477089056646 11.496213016728769 12.132696466140123 13.0249548161124 14.02288245273865 14.50775093575956 14.679130055985258 15.192336964943184 15.502199347000133 16.29952266399552 17.231728021301766 17.468410382732003 17.995911911474966 18.516058447611154 19.103517336900314 19.851387041991664 20.075180702257853 */ public class MainClass { public static void main(String args[]) { double sum = 0; while(true) { sum += Math.random(); System.out.println(sum); if(sum > 20) break; } } }