jeudi 24 décembre 2015

How to display the elements stored in an integer arraylist?

I've tried running this code for several times (re-opening eclipse IDE) but this doesn't change anything, the code simply won't run.. This a part of a PRNG.I've even tried to run the comment alone but all i get is[]System.out.println(objprng2.clcg(2,10,50,44,54,67,6,6,4,6,2,5,5,4,5,5,4,5));

package Firstage;

import java.util.*;

public class prng2 {

static List<Integer> seq = new ArrayList<>();

public List<Integer> clcg(int mul_1,int seed_1,int inc_1,int mod_1,int mul_2,int seed_2,int inc_2,int mod_2,int mul_3,int seed_3,int inc_3,int mod_3,int mul_4,int seed_4,int inc_4,int mod_4,int newno,int more)
{
    int a1=(4*mul_1)+1;
    int c1=(2*inc_1)-1;
    int m1=(int) Math.pow(2,(mod_1 +more));

    int a2=(4*mul_2)+1;
    int c2=(2*inc_2)-1;
    int m2=(int)Math.pow(2,(mod_2 +more));

    int a3=(4*mul_3)+1;
    int c3=(2*inc_3)-1;
    int m3=(int)Math.pow(2,(mod_3 +more));

    int a4=(4*mul_4)+1;
    int c4=(2*inc_4)-1;
    int m4=(int)Math.pow(2,(mod_4 +more));

    int X=0;

    int period=(((m1)-1)*((m2)-1)*((m3)-1)*((m4)-1))/8;
    int pc=0;
    int newlim=0;

    while (pc < period)
    {
        int i=1;
        int p=0;
        seed_1= ((a1 * seed_1)+c1)%m1;
        seed_2= ((a2 * seed_2)+c2)%m2;
        seed_3= ((a3 * seed_3)+c3)%m3;
        seed_4= ((a4 * seed_4)+c4)%m4;
        X=((seed_1)+(seed_2)+(seed_3)+(seed_4))% ((m1)-1);
        int R = X % 256;
       // System.out.println("for the "+i+" time R: "+R+" seq:"+seq.get(p) );
        seq.add(R);

        newlim= newlim + 1;
        if (newlim == newno)
           {
            break;
           }               
        else
            {
            pc=pc+1;
            }
   // i++;
   // p++;
    }
    return seq;
    }

public static void main (String[] args)
{
    prng2 objprng2 = new prng2();
    objprng2.clcg(2,10,50,44,54,67,6,6,4,6,2,5,5,4,5,5,4,5);
    //System.out.println(objprng2.clcg(2,10,50,44,54,67,6,6,4,6,2,5,5,4,5,5,4,5));

        for(Integer element : seq) 
{   
        System.out.print((element));
} 
}
}




Aucun commentaire:

Enregistrer un commentaire