1 19 package org.objectweb.carol.cmi; 20 21 import java.net.InetAddress ; 22 import java.net.UnknownHostException ; 23 24 public class SecureRandom { 25 private static java.security.SecureRandom sr = null; 26 27 private static java.security.SecureRandom getSR() { 28 if (sr != null) 29 return sr; 30 sr = new java.security.SecureRandom (); 31 sr.setSeed(System.currentTimeMillis()); 32 try { 33 sr.setSeed(InetAddress.getLocalHost().getAddress()); 34 } catch (UnknownHostException e) { 35 } 37 return sr; 38 } 39 40 public static void setSeed(long rs) { 41 getSR().setSeed(rs); 42 } 43 44 public static void setSeed(byte[] rs) { 45 getSR().setSeed(rs); 46 } 47 48 public static int getInt() { 49 return getSR().nextInt(); 50 } 51 52 58 public static int getInt(int n) { 59 return getSR().nextInt(n); 60 } 61 62 public static long getLong() { 63 return getSR().nextLong(); 64 } 65 } 66 | Popular Tags |