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 Implement Binomial Tree
Spring Data JPA @Query
Java Program to Perform Searching in a 2-Dimension K-D Tree
Java Program to Implement Cubic convergence 1/pi Algorithm
Vector trong Java
Java Program to Perform Insertion in a BST
Prevent Cross-Site Scripting (XSS) in a Spring Application
Checking for Empty or Blank Strings in Java
Sử dụng Fork/Join Framework với ForkJoinPool trong Java
Convert Hex to ASCII in Java
Finding the Differences Between Two Lists in Java
Java Program to Print the Kind of Rotation the AVL Tree is Undergoing
Hướng dẫn sử dụng Java Generics
Form Validation with AngularJS and Spring MVC
Introduction to Netflix Archaius with Spring Cloud
Spring 5 and Servlet 4 – The PushBuilder
Guide to ThreadLocalRandom in Java
Java Program to Compute the Volume of a Tetrahedron Using Determinants
Java Program to Find a Good Feedback Edge Set in a Graph
Merging Streams in Java
Java Program to Implement Hash Tree
Programmatic Transaction Management in Spring
Using JWT with Spring Security OAuth (legacy stack)
Queue và PriorityQueue trong Java
Spring Boot - Thymeleaf
Jackson Ignore Properties on Marshalling
Logout in an OAuth Secured Application
The HttpMediaTypeNotAcceptableException in Spring MVC
Java Program to Compute Cross Product of Two Vectors
Filtering and Transforming Collections in Guava
Removing all Nulls from a List in Java
Spring 5 WebClient