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:
Hướng dẫn Java Design Pattern – Chain of Responsibility
Mapping Nested Values with Jackson
Java – Reader to String
Registration with Spring Security – Password Encoding
Using Java Assertions
Các kiểu dữ liệu trong java
Apache Commons Collections OrderedMap
Exception Handling in Java
Java Program to Implement PrinterStateReasons API
Model, ModelMap, and ModelAndView in Spring MVC
Guide to Dynamic Tests in Junit 5
Introduction to Spring Cloud CLI
Registration – Password Strength and Rules
Java Program to Implement Affine Cipher
Intersection of Two Lists in Java
Java Program to Test Using DFS Whether a Directed Graph is Strongly Connected or Not
Java Program to Implement Meldable Heap
Java Program to Implement VList
Tạo ứng dụng Java RESTful Client với thư viện Retrofit
Java Program to Perform LU Decomposition of any Matrix
Java Program for Douglas-Peucker Algorithm Implementation
Jackson – Unmarshall to Collection/Array
Java Program to Implement LinkedBlockingQueue API
Java Program to Create the Prufer Code for a Tree
Spring Boot - Enabling HTTPS
The Modulo Operator in Java
An Example of Load Balancing with Zuul and Eureka
Java Program to Implement vector
Java Program to Implement Max Heap
Java Program to Implement Fibonacci Heap
Call Methods at Runtime Using Java Reflection
Java Program to Implement Hash Tables Chaining with Binary Trees