Multiplicative Congruence method for generating Pseudo Random Numbers | Java implementation of the above approach ; Function to generate random numbers ; Initialize the seed state ; Traverse to generate required numbers of random numbers ; Follow the multiplicative congruential method ; Driver code ; Seed value ; Modulus parameter ; Multiplier term ; Number of Random numbers to be generated ; To store random numbers ; Function Call ; Print the generated random numbers
import java . util . * ; class GFG { static void multiplicativeCongruentialMethod ( int Xo , int m , int a , int [ ] randomNums , int noOfRandomNums ) { randomNums [ 0 ] = Xo ; for ( int i = 1 ; i < noOfRandomNums ; i ++ ) { randomNums [ i ] = ( randomNums [ i - 1 ] * a ) % m ; } } public static void main ( String [ ] args ) { int Xo = 3 ; int m = 15 ; int a = 7 ; int noOfRandomNums = 10 ; int [ ] randomNums = new int [ noOfRandomNums ] ; multiplicativeCongruentialMethod ( Xo , m , a , randomNums , noOfRandomNums ) ; for ( int i = 0 ; i < noOfRandomNums ; i ++ ) { System . out . print ( randomNums [ i ] + " ▁ " ) ; } } }