Author: nextgens
Date: 2008-11-18 18:59:45 +0000 (Tue, 18 Nov 2008)
New Revision: 23737

Modified:
   trunk/contrib/java/org/spaceroots/mantissa/random/MersenneTwister.java
Log:
DOH. fix the seeding

Modified: trunk/contrib/java/org/spaceroots/mantissa/random/MersenneTwister.java
===================================================================
--- trunk/contrib/java/org/spaceroots/mantissa/random/MersenneTwister.java      
2008-11-18 17:41:53 UTC (rev 23736)
+++ trunk/contrib/java/org/spaceroots/mantissa/random/MersenneTwister.java      
2008-11-18 18:59:45 UTC (rev 23737)
@@ -151,16 +151,25 @@
                }
                int[] seeds = new int[seed.length/4];
                for(int i=0;i<seeds.length;i+=4) {
-                       int x = 0;
-                       for(int j = 3; j >= 0; j--) {
-                               int y = (seed[j + i * 4] & 0xff);
-                               x = (x << 8) | y;
-                       }
-                       seeds[i] = x;
+                       seeds[i] = MersenneTwister.bytesToInt(seed, i);
                }
                setSeed(seeds);
        }
 
+       /**
+        * A copy of our @see{freenet.support.Fields} 
+        * */
+       public static int bytesToInt(byte[] buf, int offset) {
+               if(buf.length < 4)
+                       throw new IllegalArgumentException();
+               int x = 0;
+               for(int j = 3; j >= 0; j--) {
+                       int y = (buf[j + offset] & 0xff);
+                       x = (x << 8) | y;
+               }
+               return x;
+       }
+
        /** Reinitialize the generator as if just built with the given int 
array seed.
         * <p>The state of the generator is exactly the same as a new
         * generator built with the same seed.</p>

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to