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:
Mapping a Dynamic JSON Object with Jackson
Java Program to Implement Suffix Array
Java Timer
“Stream has already been operated upon or closed” Exception in Java
Concrete Class in Java
Java Program to Create a Random Graph Using Random Edge Generation
An Intro to Spring Cloud Task
Java String to InputStream
Mix plain text and HTML content in a mail
Giới thiệu Google Guice – Dependency injection (DI) framework
Java Program to Solve the 0-1 Knapsack Problem
Java Program to Perform Deletion in a BST
Java Program to Find the Vertex Connectivity of a Graph
Java Program to Implement Fibonacci Heap
Hướng dẫn tạo và sử dụng ThreadPool trong Java
Java Program to Find the Median of two Sorted Arrays using Binary Search Approach
Spring REST API + OAuth2 + Angular
Fixing 401s with CORS Preflights and Spring Security
Spring Security Form Login
String Initialization in Java
Hướng dẫn sử dụng Java String, StringBuffer và StringBuilder
Java Program to Implement wheel Sieve to Generate Prime Numbers Between Given Range
Java Program to find the maximum subarray sum using Binary Search approach
Java Program to Implement Hash Tables Chaining with Binary Trees
New Features in Java 10
Custom Error Pages with Spring MVC
Guava CharMatcher
How to Remove the Last Character of a String?
Guide to Character Encoding
Java Program to Apply DFS to Perform the Topological Sorting of a Directed Acyclic Graph
Map to String Conversion in Java
A Guide to Java 9 Modularity