Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. package test;
  2.  
  3. import java.math.BigInteger;
  4.  
  5. import edu.tfzr.nemanja.Congruence;
  6.  
  7. public class Generators {
  8.         public Congruence cong[] = new Congruence[8]; //linear congruence RNGs
  9.        
  10.         //svih 8
  11.         public Generators(String seed) {
  12.             cong[0] = new Congruence("65539", "2147483648", seed); //m=2*31
  13.             cong[1] = new Congruence("16807", "2147483647", seed); //m=2*31-1
  14.             cong[2] = new Congruence("40692", "2147483399", seed); //m=2*31-249
  15.             cong[3] = new Congruence("48271", "2147483647", seed); //m=2*31-1
  16.             cong[4] = new Congruence("62089911", "2147483647", seed); //m=2*31-1
  17.             cong[5] = new Congruence("69069", "4294967296", seed); //m=2*32
  18.             cong[6] = new Congruence("31167285", "281474976710656", seed); //m=2*48
  19.             cong[7] = new Congruence("6364136223846793005", "18446744073709551616", seed); //m=2*64
  20.            
  21.             cong[0].count=cong.length;
  22.         }
  23.        
  24.         //sledeca vrednost
  25.         public BigInteger nextValue(int i) {
  26.             return cong[i].nextValue();
  27.         }
  28.        
  29.         //vraca double
  30.         public double doubleValue(int i) {
  31.             return cong[i].doubleValue();
  32.     }
  33.         public static void main(String[] args) {
  34.             int iCong = 7;
  35.             String seed = "39485389";
  36.             Generators gen = new Generators(seed);
  37.             //gen cong[1].count=90
  38.             System.out.println(gen.cong[5].count + " Generator: " + iCong +", multiplier: " + gen.cong[5].multiplier + ", modulus: " + gen.cong[5].modulus+", seed:" +gen.cong[5].seed);
  39.            
  40.             for(int i=0; i<3; i++) {
  41.                 BigInteger x = gen.nextValue(i);
  42.                 System.out.println(x + "\t" + gen.doubleValue(iCong));
  43.             }
  44.         }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement