1 10 11 package org.mmbase.util; 12 13 22 public class RandomPool { 23 24 31 private static long ranPool = 0x67452301efcdab89L; 32 33 41 private static long p[] = { 43 0xd76aa478e8c7b756L, 0x242070dbc1bdceeeL, 0xf57c0faf4787c62aL, 0xa8304613fd469501L, 0x698098d88b44f7afL, 0xffff5bb1895cd7beL, 0x6b901122fd987193L, 0xa679438e49b40821L, 0xf61e2562c040b340L, 0x265e5a51e9b6c7aaL, 0xd62f105d02441453L, 0xd8a1e681e7d3fbc8L, 0x21e1cde6c33707d6L, 0xf4d50d87455a14edL, 0xa9e3e905fcefa3f8L, 0x676f02d98d2a4c8aL, 0xfffa39428771f681L, 0x6d9d6122fde5380cL, 0xa4beea444bdecfa9L, 0xf6bb4b60bebfbc70L, 0x289b7ec6eaa127faL, 0xd4ef308504881d05L, 0xd9d4d039e6db99e5L, 0x1fa27cf8c4ac5665L, 0xf4292244432aff97L, 0xab9423a7fc93a039L, 0x655b59c38f0ccc92L, 0xffeff47d85845dd1L, 0x6fa87e4ffe2ce6e0L, 0xa30143144e0811a1L, 0xf7537e82bd3af235L }; 75 76 80 public RandomPool() { 81 stir(System.currentTimeMillis()); 82 } 83 84 88 public RandomPool(long init) { 89 stir(init); 90 } 91 92 98 public synchronized void stir(long x) { 99 int pIndex; 100 101 pIndex = mod(ranPool, p.length); 102 ranPool = (ranPool + x)*p[pIndex]; 103 pIndex = mod(ranPool, p.length); 104 ranPool = ranPool ^ p[pIndex]; 105 } 106 107 110 public long value() { 111 return(ranPool); 112 } 113 114 119 public long value_and_stir() { 120 stir(System.currentTimeMillis()); 121 return(ranPool); 122 } 123 124 128 public long value_and_stir(long mix) { 129 stir(mix); 130 return(ranPool); 131 } 132 133 139 private int mod (long x, long y) { 140 if (x<0) x=-x; 141 if (y<0) y=-y; 142 return (int) (x % y); 143 } 144 } 145 146 | Popular Tags |