1 16 package org.apache.commons.lang.math; 17 18 import java.util.Random ; 19 20 29 public final class JVMRandom extends Random { 30 31 34 private boolean constructed = false; 35 36 39 public JVMRandom() { 40 this.constructed = true; 41 } 42 43 49 public synchronized void setSeed(long seed) { 50 if (this.constructed) { 51 throw new UnsupportedOperationException (); 52 } 53 } 54 55 61 public synchronized double nextGaussian() { 62 throw new UnsupportedOperationException (); 63 } 64 65 71 public void nextBytes(byte[] byteArray) { 72 throw new UnsupportedOperationException (); 73 } 74 75 81 public int nextInt() { 82 return nextInt(Integer.MAX_VALUE); 83 } 84 93 public int nextInt(int n) { 94 if (n <= 0) { 95 throw new IllegalArgumentException ( 96 "Upper bound for nextInt must be positive" 97 ); 98 } 99 return (int)(Math.random() * n); 101 } 102 107 public long nextLong() { 108 return nextLong(Long.MAX_VALUE); 110 } 111 112 113 122 public static long nextLong(long n) { 123 if (n <= 0) { 124 throw new IllegalArgumentException ( 125 "Upper bound for nextInt must be positive" 126 ); 127 } 128 return (long)(Math.random() * n); 130 } 131 132 138 public boolean nextBoolean() { 139 return Math.random() > 0.5; 140 } 141 148 public float nextFloat() { 149 return (float)Math.random(); 150 } 151 156 public double nextDouble() { 157 return Math.random(); 158 } 159 160 } 161 | Popular Tags |