Java Program to Implement Naor-Reingold Pseudo Random Function Last Updated : 04 Dec, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 = 5 Output: 9.0, 9.0, 3.0, 9.0, 3.0 Input : N = 7 Output: 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 numbersGenerate 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)=ga0.a1x1a2x2…..anxn ε FpPrint 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(); } } OutputThe Random numbers are: 9.0, 9.0, 3.0, 81.0, 3.0, 81.0, 9.0, 9.0, 3.0, 3.0, Comment More infoAdvertise with us Next Article Java Program to Implement the Linear Congruential Generator for Pseudo Random Number Generation R rbbansal Follow Improve Article Tags : Java Java Programs Practice Tags : Java Similar Reads Java Program to Implement the Linear Congruential Generator for Pseudo Random Number Generation Linear Congruential Method is a class of Pseudo-Random Number Generator (PRNG) algorithms used for generating sequences of random-like numbers in a specific range. This method can be defined as: Xi+1 = aXi + c mod m where, X, is the sequence of pseudo-random numbers m, ( > 0) the modulus a, (0, m 3 min read Java Program to Implement Park-Miller Random Number Generation Algorithm ParkâMiller random number generator is also known as Lehmer random number generator. A general formula of a random number generator (RNG) of this type is, Xk+1 = a * xk mod m Where the modulus m is a prime number or a power of a prime number, the multiplier a is an element of high multiplicative ord 3 min read Java Program to Implement Inversion Method for Random Number Generation Here we will be going through the inversion method for random number generation in java. So basically we will be illustrating two approaches which are as follows: Shuffling elements in an arrayUsing Collection.shuffle() method Important Method here namely is setSeed(). It is used to set the seed via 9 min read Java Program For Selecting A Random Node From A Singly Linked List Given a singly linked list, select a random node from the linked list (the probability of picking a node should be 1/N if there are N nodes in the list). You are given a random number generator.Below is a Simple Solution: Count the number of nodes by traversing the list.Traverse the list again and s 4 min read Java Program to Generate Random Hexadecimal Bytes To generate Random Hexadecimal Bytes, first, a random byte can be generated in decimal form using Java.util.Random.nextInt() and then it can be converted to hexadecimal form using Integer.toHexString() method. 1. Java.util.Random.nextInt() The nextInt() method is used to obtain the next integer from 2 min read Java Program to Generate Random Numbers Using Multiply with Carry Method In computer science, multiply-with-carry (MWC) is a method invented by George Marsaglia for generating sequences of random integers based on an initial set from two to many thousands of randomly chosen seed values. The main advantage of the MWC method is that it invokes simple computer integer arith 2 min read Like