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.

//This is a java program to generate a random numbers using Naor-Reingold Psedurandom Function
import java.util.Random;
 
public class Naor_Reingold 
{
    public static void main(String args[])
    {
        int p=7, l=3, g=2, n=4, x;
        int []a = {1,2,2,1};
        int []bin = new int[4];
        Random random = new Random();
        System.out.println("The Random numbers are: ");
        for(int i=0; i<10; i++)
        {
            x = random.nextInt(17);
            for(int j=3; j>=0; j--)
            {
                bin[j] = x%2;
                x/=2;
            }
            int mul = 1;
            for(int k=0; k<4; k++)
                mul *= Math.pow(a[k], bin[k]);
            System.out.println(Math.pow(g, mul));
        }
    }
}

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

Related posts:

Java Program to Implement Fermat Factorization Algorithm
Java Program to Find Shortest Path Between All Vertices Using Floyd-Warshall’s Algorithm
Hướng dẫn Java Design Pattern – Intercepting Filter
Java Program to do a Depth First Search/Traversal on a graph non-recursively
Hướng dẫn Java Design Pattern – Template Method
Java Program to Implement ArrayList API
Java Program to Generate All Subsets of a Given Set in the Lexico Graphic Order
A Quick Guide to Using Keycloak with Spring Boot
Spring Boot - Rest Template
Java Program to Check if a Given Set of Three Points Lie on a Single Line or Not
Convert String to int or Integer in Java
Java Program to Perform Searching in a 2-Dimension K-D Tree
Weak References in Java
A Guide to Java HashMap
Java Program to Delete a Particular Node in a Tree Without Using Recursion
Sort a HashMap in Java
Error Handling for REST with Spring
Java Program to Implement the Monoalphabetic Cypher
Chuyển đổi Array sang ArrayList và ngược lại
Jackson – Bidirectional Relationships
Rest Web service: Filter và Interceptor với Jersey 2.x (P1)
Java Program to Perform Preorder Non-Recursive Traversal of a Given Binary Tree
Life Cycle of a Thread in Java
Mệnh đề if-else trong java
Java Program to Implement Sorted Vector
Introduction to Spring Boot CLI
Java Program to Implement RenderingHints API
The Modulo Operator in Java
Introduction to Spring Data JPA
Java Program to Implement Stack
Ways to Iterate Over a List in Java
Tính trừu tượng (Abstraction) trong Java