Friday, 17 November 2017

Java Program to Implement the linear congruential generator for Pseudo Random Number Generation


Code:

import java.math.BigInteger;
import java.util.Random;

public class Linear_Congruential_Random_Numbers 
{
    public static void main(String args[])
    {
        BigInteger n = new BigInteger(16, new Random(){});
        Random rand = new Random();
        BigInteger m = new BigInteger("65535");//2^16

        for(int i=0; i<5 font="" i="">
        {
            System.out.print(n+", ");
            BigInteger a = new BigInteger(16, new Random(){});
            BigInteger c = new BigInteger(16, new Random(){});
            n = ((a.multiply(a)).add(c)).mod(m);
        }
        System.out.println("... ");
    }
}

Output:

5107, 48257, 43654, 50875, 12815, ...


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...