RandomExample -- using Math.random() to
generate random float and int values within
predefined ranges.
To see this example in action:
- Compile the Java source file, RandomExample.java:
javac RandomExample.java
- Run the class:
java RandomExample
Output (for one run; your output had better be different!):
floatVal = 8.89418
floatVal = 5.9651604
floatVal = 4.0838327
floatVal = -4.2632303
floatVal = 7.7349434
floatVal = -1.9211664
floatVal = 3.2794933
floatVal = 4.8795376
floatVal = -7.094227
floatVal = 6.359726
intVal = 60
intVal = 43
intVal = 72
intVal = 38
intVal = 46
intVal = 1
intVal = 41
intVal = 82
intVal = 48
intVal = 64
The source.