2016-08-09 10:21:47 -06:00
|
|
|
// control/RandomBounds.java
|
2015-12-15 11:47:04 -08:00
|
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
2015-11-15 15:51:35 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2015-06-15 17:47:35 -07:00
|
|
|
// Does Math.random() produce 0.0 and 1.0?
|
2016-07-28 13:42:03 -06:00
|
|
|
// {java RandomBounds lower}
|
2016-07-07 14:58:56 -06:00
|
|
|
import onjava.*;
|
2015-06-15 17:47:35 -07:00
|
|
|
|
|
|
|
public class RandomBounds {
|
|
|
|
public static void main(String[] args) {
|
2016-07-07 14:58:56 -06:00
|
|
|
new TimedAbort(3);
|
2016-08-09 10:21:47 -06:00
|
|
|
switch(args.length == 0 ? "" : args[0]) {
|
2015-06-15 17:47:35 -07:00
|
|
|
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:
|
2016-08-09 10:21:47 -06:00
|
|
|
System.out.println("Usage:");
|
|
|
|
System.out.println("\tRandomBounds lower");
|
|
|
|
System.out.println("\tRandomBounds upper");
|
|
|
|
System.exit(1);
|
2015-06-15 17:47:35 -07:00
|
|
|
}
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|