# Java Program to Implement Naor-Reingold Pseudo Random Function

«
»
This is a java program generate pseudo-random numbers using Naor-Reingold Pseudo-Random function. Let p and l be prime numbers with l |p-1. Select an element g in Fp of multiplicative order l. Then for each n-dimensional vector a = (a1, …, an). Fa(x) = g^(a1^x1 * a2^x2 …).

Here is the source code of the Java Program to Implement Naor-Reingold Pseudo Random Function. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

1. `//This is a java program to generate a random numbers using Naor-Reingold Psedurandom Function`
2. `import java.util.Random;`
3. ` `
4. `public class Naor_Reingold `
5. `{`
6. `    public static void main(String args[])`
7. `    {`
8. `        int p=7, l=3, g=2, n=4, x;`
9. `        int []a = {1,2,2,1};`
10. `        int []bin = new int;`
11. `        Random random = new Random();`
12. `        System.out.println("The Random numbers are: ");`
13. `        for(int i=0; i<10; i++)`
14. `        {`
15. `            x = random.nextInt(17);`
16. `            for(int j=3; j>=0; j--)`
17. `            {`
18. `                bin[j] = x%2;`
19. `                x/=2;`
20. `            }`
21. `            int mul = 1;`
22. `            for(int k=0; k<4; k++)`
23. `                mul *= Math.pow(a[k], bin[k]);`
24. `            System.out.println(Math.pow(g, mul));`
25. `        }`
26. `    }`
27. `}`

Output:

```\$ javac Naor_Reingold.java
\$ java Naor_Reingold
The Random numbers are:
2.0
4.0
2.0
2.0
2.0
16.0
4.0
16.0
16.0
4.0```

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now! 