32 lines
782 B
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// containersindepth/RandomBounds.java
2015-06-15 17:47:35 -07:00
// Does Math.random() produce 0.0 and 1.0?
// {TimeOutDuringTesting}
// {Args: lower}
public class RandomBounds {
static void usage() {
2015-11-03 12:00:44 -08:00
System.out.println("Usage:");
System.out.println("\tRandomBounds lower");
System.out.println("\tRandomBounds upper");
2015-06-15 17:47:35 -07:00
System.exit(1);
}
public static void main(String[] args) {
if(args.length != 1) usage();
switch(args[0]) {
case "lower":
while(Math.random() != 0.0)
; // Keep trying
2015-11-03 12:00:44 -08:00
System.out.println("Produced 0.0!");
2015-06-15 17:47:35 -07:00
break;
case "upper":
while(Math.random() != 1.0)
; // Keep trying
2015-11-03 12:00:44 -08:00
System.out.println("Produced 1.0!");
2015-06-15 17:47:35 -07:00
break;
default:
usage();
}
}
2015-09-07 11:44:36 -06:00
}
/* Output: (None) */