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 Perform Uniform Binary Search
Get the workstation name or IP
Spring Boot Configuration with Jasypt
Java Program to Implement Suffix Array
Giới thiệu về Stream API trong Java 8
Java Program to Convert a Decimal Number to Binary Number using Stacks
Intro to the Jackson ObjectMapper
Reactive Flow with MongoDB, Kotlin, and Spring WebFlux
A Guide to TreeSet in Java
Giới thiệu Google Guice – Aspect Oriented Programming (AOP)
Java Program to implement Dynamic Array
Iterating over Enum Values in Java
Spring Boot - Servlet Filter
Spring Webflux and CORS
Java Program to Find a Good Feedback Vertex Set
Java Program to Implement ArrayDeque API
Performance Difference Between save() and saveAll() in Spring Data
Generating Random Dates in Java
Java Program to Repeatedly Search the Same Text (such as Bible by building a Data Structure)
Java Program to Check Cycle in a Graph using Topological Sort
An Introduction to Java.util.Hashtable Class
Control the Session with Spring Security
Guide to java.util.concurrent.Locks
Java Program to Implement Bellman-Ford Algorithm
Object Type Casting in Java
Hướng dẫn Java Design Pattern – Decorator
Simple Single Sign-On with Spring Security OAuth2
Sort a HashMap in Java
String Joiner trong Java 8
Java Program to Describe the Representation of Graph using Adjacency List
Handle EML file with JavaMail
String Processing with Apache Commons Lang 3