From: <ke...@us...> - 2003-03-28 02:46:05
|
Update of /cvsroot/webmacro/webmacro/src/org/webmacro/servlet In directory sc8-pr-cvs1:/tmp/cvs-serv24328 Modified Files: MathTool.java Log Message: Fixed bug in random(). Added main method with a test. Index: MathTool.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/servlet/MathTool.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MathTool.java 10 Nov 2002 21:26:54 -0000 1.5 --- MathTool.java 28 Mar 2003 02:46:00 -0000 1.6 *************** *** 99,103 **** */ public static final int random(int start, int end) { ! return start + (int) (end *java.lang.Math.random()/(Integer.MAX_VALUE+1.0)); } --- 99,103 ---- */ public static final int random(int start, int end) { ! return start + (int)((end - start + 1) * java.lang.Math.random()); } *************** *** 186,189 **** --- 186,198 ---- */ public void destroy(Object o) { + } + + public static void main(String[] args){ + System.out.println("Generating 200 random ints between 10 and 99 inclusive:"); + for (int i=0; i<200; i++){ + System.out.print(MathTool.random(10, 99) + " "); + if (((i + 1) % 20) == 0) System.out.println(); + } + System.out.println("\nDone."); } } |