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:

Introduction to Spring Cloud CLI
Quick Guide to Spring MVC with Velocity
Converting Between an Array and a Set in Java
Apache Commons Collections Bag
Java Program to Implement Stack using Linked List
Java Stream Filter with Lambda Expression
Java Program to Implement Red Black Tree
Java Program to Solve any Linear Equation in One Variable
The Registration Process With Spring Security
Giới thiệu về Stream API trong Java 8
Truyền giá trị và tham chiếu trong java
Bootstrapping Hibernate 5 with Spring
Từ khóa static và final trong java
Tìm hiểu về xác thực và phân quyền trong ứng dụng
Java Program to Check Whether a Weak Link i.e. Articulation Vertex Exists in a Graph
Java Program to Check Cycle in a Graph using Topological Sort
Java Program to Implement TreeMap API
How to Manually Authenticate User with Spring Security
Intro to Inversion of Control and Dependency Injection with Spring
Working With Maps Using Streams
Spring Data Reactive Repositories with MongoDB
Lập trình hướng đối tượng (OOPs) trong java
Serialize Only Fields that meet a Custom Criteria with Jackson
Guide to java.util.Formatter
Tổng quan về ngôn ngữ lập trình java
Convert char to String in Java
Java Program to Implement Variable length array
Java Program to Implement the Edmond’s Algorithm for Maximum Cardinality Matching
Java Program to Implement HashSet API
Display Auto-Configuration Report in Spring Boot
Shuffling Collections In Java
Java Program to Implement the Monoalphabetic Cypher