Math: random() : Math « java.lang « Java by API

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;
}
}
}

```

Related examples in the same category

 1 Math.E 2 Math.PI 3 Math: abs(int value) 4 Math.cbrt(double a) Returns the cube root of a double value. 5 Math: ceil(float value) 6 Math: copySign(double magnitude, double sign) 7 Math: cos(double doubleValue) 8 Math: exp(double a) 9 Math: floor(float value) 10 Math: getExponent(double d) 11 Math.hypot(double x, double y) Returns sqrt(x2 +y2) without intermediate overflow or underflow. 12 Math: log(double doubleValue) 13 Math.log10(double a) 14 Math: max(int value1, int value2) 15 Math: min(double a, double b) 16 Math: min(int value1, int value2) 17 Math: nextAfter(double start, double direction) 18 Math: nextUp(double d) 19 Math: pow(int a, int b) 20 Math.round(double a) 21 Math: scalb(double d, int scaleFactor) 22 Math.signum(float f) 23 Math: sin(double doubleValue) 24 Math.sqrt(int intValue) 25 Math: tan(double doubleValue) 26 Math: toDegrees(double theta) 27 Math: toRadians(double theta)