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:
How to Round a Number to N Decimal Places in Java
Spring MVC Setup with Kotlin
Functional Interface trong Java 8
Logging a Reactive Sequence
Guide to Guava Multimap
A Guide to TreeSet in Java
The DAO with Spring and Hibernate
Java Program to Implement Cubic convergence 1/pi Algorithm
Biểu thức Lambda trong Java 8 – Lambda Expressions
Spring Data Java 8 Support
Java Program to find the maximum subarray sum O(n^2) time(naive method)
The StackOverflowError in Java
Spring Boot - Enabling Swagger2
What is a POJO Class?
Java Program to Find the Connected Components of an UnDirected Graph
Lớp LinkedHashMap trong Java
REST Pagination in Spring
Java Program to Implement Slicker Algorithm that avoids Triangulation to Find Area of a Polygon
Java Program to Generate a Random UnDirected Graph for a Given Number of Edges
Tạo ứng dụng Java RESTful Client với thư viện OkHttp
Java Program to Implement Sieve Of Sundaram
Error Handling for REST with Spring
Prevent Brute Force Authentication Attempts with Spring Security
A Guide to BitSet in Java
Java Program to Implement Dijkstra’s Algorithm using Set
Java Program to Check if a Given Graph Contain Hamiltonian Cycle or Not
Spring Cloud Series – The Gateway Pattern
Java Program to Solve TSP Using Minimum Spanning Trees
Giới thiệu Google Guice – Dependency injection (DI) framework
New Features in Java 14
A Guide to Spring Boot Admin
Java Program to Generate a Graph for a Given Fixed Degree Sequence