Naor-Reingold Pseudo-Random Function is a function of generating random numbers. Moni Naor and Omer Reingold described efficient constructions for various cryptographic primitives in the private key as well as public-key cryptography.

**Example:**

Input :N = 5Output:9.0, 9.0, 3.0, 9.0, 3.0Input :N = 7Output:9.0, 81.0, 9.0, 9.0, 3.0, 3.0, 9.0

**Algorithm:**

- Declare the variables p, l, g, n, x and arrays a[] and arr[]
- Take input from the user for generating random numbers
- Generate random numbers and use the defined approach:

Let p and l be prime numbers with l|p−1. Select an element g ε Fp* of multiplicative order l. Then for each n-dimensional vector a = (a0,a1, ..., an). They define the function as: fa(x)=g^{a0.a1x1a2x2…..anxn}ε Fp

- Print the random numbers

Below is the implementation of the Naor-Reingold Pseudo-Random Function:

## Java

`// Java Program to Implement Naor-Reingold` `// Pseudo Random Function` `import` `java.util.*;` `public` `class` `Main {` ` ` `public` `static` `void` `randomNumbers()` ` ` `{` ` ` `// Creating arrays and defining variables` ` ` `int` `p = ` `7` `, l = ` `2` `, g = ` `3` `, n = ` `6` `, x;` ` ` ` ` `int` `a[] = { ` `1` `, ` `2` `, ` `2` `, ` `1` `};` ` ` ` ` `int` `arr[] = ` `new` `int` `[` `4` `];` ` ` ` ` `Random random = ` `new` `Random();` ` ` ` ` `int` `num = ` `10` `;` ` ` `System.out.println(` `"The Random numbers are: "` `);` ` ` ` ` `// Generating Random Numbers using` ` ` `// Naor-Reingold Pseudo Random Function approach` ` ` `for` `(` `int` `i = ` `0` `; i < num; i++) {` ` ` `x = random.nextInt(num) % ` `16` `;` ` ` ` ` `for` `(` `int` `j = ` `3` `; j >= ` `0` `; j--) {` ` ` `arr[j] = x % ` `2` `;` ` ` `x /= ` `2` `;` ` ` `}` ` ` `int` `mult = ` `1` `;` ` ` ` ` `for` `(` `int` `k = ` `0` `; k < ` `4` `; k++) {` ` ` `mult *= Math.pow(a[k], arr[k]);` ` ` `}` ` ` `System.out.print(Math.pow(g, mult) + ` `", "` `);` ` ` `}` ` ` `}` ` ` `public` `static` `void` `main(String args[])` ` ` `{` ` ` `randomNumbers();` ` ` `}` `}` |

**Output**

The Random numbers are: 9.0, 9.0, 3.0, 81.0, 3.0, 81.0, 9.0, 9.0, 3.0, 3.0,

Attention reader! Don’t stop learning now. Get hold of all the important **Java Foundation** and Collections concepts with the **Fundamentals of Java and Java Collections Course** at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer **Complete Interview Preparation Course****.**