OnJava8-Examples/containers/RandomBounds.java

33 lines
778 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: containers/RandomBounds.java
2015-05-29 14:18:51 -07:00
// <20>2015 MindView LLC: see Copyright.txt
2015-04-20 15:36:01 -07:00
// Does Math.random() produce 0.0 and 1.0?
2015-05-05 11:20:13 -07:00
// {TimeOutDuringTesting}
// {Args: lower}
2015-04-20 15:36:01 -07:00
import static net.mindview.util.Print.*;
public class RandomBounds {
static void usage() {
print("Usage:");
print("\tRandomBounds lower");
print("\tRandomBounds upper");
System.exit(1);
}
public static void main(String[] args) {
if(args.length != 1) usage();
2015-05-05 11:20:13 -07:00
switch(args[0]) {
case "lower":
while(Math.random() != 0.0)
; // Keep trying
print("Produced 0.0!");
break;
case "upper":
while(Math.random() != 1.0)
; // Keep trying
print("Produced 1.0!");
break;
default:
usage();
2015-04-20 15:36:01 -07:00
}
}
} ///:~