1 package org.objectweb.proactive.ext.security.crypto; 31 32 import java.security.*; 33 34 35 public class RandomLongGenerator { 36 private byte[] seed; 37 private SecureRandom secureRandom; 38 39 public RandomLongGenerator() { 40 secureRandom = new SecureRandom(); 41 } 42 43 public long generateLong(int nbBytes) { 44 if (nbBytes > 8) { 45 nbBytes = 8; 46 } 47 48 seed = new byte[nbBytes]; 49 seed = secureRandom.generateSeed(nbBytes); 50 51 long ra2 = 0; 52 53 for (int i = 0; i < 4; i++) { 54 ra2 = ra2 + 55 ((Math.abs(new Byte (seed[i]).longValue())) * new Double (Math.pow( 56 10, (-3 + (3 * (i + 1))))).longValue()); 57 } 58 59 return ra2; 60 } 61 } 62 | Popular Tags |