Friday, 17 November 2017

Java Program to Implement Park-Miller Random Number Generation Algorithm


Code:

public class Park_Miller_Random_Numbers 
{
    static final long m = 2147483647L;
    static final long a = 48271L;
    static final long q = 44488L;
    static final long r = 3399L;

    static long r_seed = 12345678L; 

    public static double uniform ()
    {
        long hi = r_seed / q;
        long lo = r_seed - q * hi;
        long t = a * lo - r * hi;
        if (t > 0)
            r_seed = t;
        else
            r_seed = t + m;
        return r_seed;
    }

    public static void main (String[] argv)
    {
        double[] A = new double [10];

        for (int i=0; i<5 font="" i="" nbsp="">
            A[i] = uniform();

        for (int i=0; i<5 font="" i="" nbsp="">
            System.out.print ("  " + A[i]);    
    }
}


Output:

1.085252519E9  5.08259731E8  1.352291773E9  1.563240271E9  8.90733155E8 ...



More Java Programs:













100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...