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:
Spring Boot - Servlet Filter
Java Program to Implement Weight Balanced Tree
HttpClient 4 – Follow Redirects for POST
So sánh HashMap và Hashtable trong Java
Java Program to Implement Binomial Tree
Introduction to Using FreeMarker in Spring MVC
The Order of Tests in JUnit
Spring MVC Async vs Spring WebFlux
Java Program to Perform Searching Using Self-Organizing Lists
Java Program to Perform Preorder Recursive Traversal of a Given Binary Tree
Introduction to Eclipse Collections
Java Program to Implement ScapeGoat Tree
Spring REST API + OAuth2 + Angular
Java – Write a Reader to File
Java Program to Perform Postorder Non-Recursive Traversal of a Given Binary Tree
Convert a Map to an Array, List or Set in Java
Spring AMQP in Reactive Applications
Java Program to Implement Merge Sort on n Numbers Without tail-recursion
Upload and Display Excel Files with Spring MVC
Setting the Java Version in Maven
Java Program to Find Number of Spanning Trees in a Complete Bipartite Graph
Java Program to Find the Shortest Path Between Two Vertices Using Dijkstra’s Algorithm
Java 9 Stream API Improvements
Java Program to Solve the 0-1 Knapsack Problem
Java Program to Check Whether a Given Point is in a Given Polygon
Introduction to the Java ArrayDeque
The Registration Process With Spring Security
Java Program to Implement Graph Coloring Algorithm
Java – Combine Multiple Collections
Java – File to Reader
Java Program to Perform Left Rotation on a Binary Search Tree
Comparing Strings in Java