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:
Batch Processing with Spring Cloud Data Flow
SOAP Web service: Authentication trong JAX-WS
Java Optional as Return Type
Apache Commons Collections Bag
LinkedHashSet trong java
Java Program to Check if a Given Set of Three Points Lie on a Single Line or Not
Spring MVC Tutorial
Different Ways to Capture Java Heap Dumps
Java – Write to File
Changing Annotation Parameters At Runtime
Primitive Type Streams in Java 8
Java Program to Implement LinkedBlockingDeque API
How to use the Spring FactoryBean?
Working With Maps Using Streams
Java Program to Check whether Graph is Biconnected
Java Program to Implement Graham Scan Algorithm to Find the Convex Hull
Create a Custom Exception in Java
Tạo ứng dụng Java RESTful Client không sử dụng 3rd party libraries
Migrating from JUnit 4 to JUnit 5
Date Time trong Java 8
Java Program to Generate a Graph for a Given Fixed Degree Sequence
Java Program to Create a Balanced Binary Tree of the Incoming Data
Java Program to Represent Graph Using 2D Arrays
Initialize a HashMap in Java
Model, ModelMap, and ModelAndView in Spring MVC
String Joiner trong Java 8
@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll
A Guide to Iterator in Java
Java Program to Implement Queue using Two Stacks
Call Methods at Runtime Using Java Reflection
Jackson JSON Views
Java Program to Check whether Graph is a Bipartite using DFS