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:
Marker Interface trong Java
Giới thiệu Google Guice – Binding
Java Program to Check if a Given Set of Three Points Lie on a Single Line or Not
A Guide to the finalize Method in Java
Convert Hex to ASCII in Java
Java Program to Implement Adjacency List
Java Program to Find k Numbers Closest to Median of S, Where S is a Set of n Numbers
How to Find an Element in a List with Java
Java Program to Construct an Expression Tree for an Infix Expression
Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java
Java Program to implement Bi Directional Map
The Difference Between Collection.stream().forEach() and Collection.forEach()
Removing all Nulls from a List in Java
@DynamicUpdate with Spring Data JPA
Using the Map.Entry Java Class
Java Program to Implement Hash Tables with Quadratic Probing
Creating a Custom Starter with Spring Boot
Spring @RequestParam Annotation
How to Read a Large File Efficiently with Java
Java Program to Implement Quick Sort Using Randomization
Guide to PriorityBlockingQueue in Java
Spring Boot With H2 Database
Spring Security – Reset Your Password
Java Program to Perform integer Partition for a Specific Case
Xử lý ngoại lệ trong Java (Exception Handling)
ETags for REST with Spring
A Guide to HashSet in Java
Hướng dẫn Java Design Pattern – Interpreter
Control Structures in Java
Java Program to Implement ConcurrentHashMap API
Java Program to Describe the Representation of Graph using Adjacency List
Using the Not Operator in If Conditions in Java