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 Check whether Undirected Graph is Connected using DFS
Java Program to Find Location of a Point Placed in Three Dimensions Using K-D Trees
Tips for dealing with HTTP-related problems
Java Program to Implement Ternary Search Algorithm
Converting Strings to Enums in Java
Spring RestTemplate Request/Response Logging
Guide to Selenium with JUnit / TestNG
How to Add a Single Element to a Stream
A Guide to WatchService in Java NIO2
Spring Boot With H2 Database
Java Program to Solve any Linear Equations
Java Program to Implement Pagoda
Spring Boot - Logging
Java Program to Perform the Sorting Using Counting Sort
Changing Annotation Parameters At Runtime
New Stream Collectors in Java 9
Template Engines for Spring
Enum trong java
Convert Time to Milliseconds in Java
Posting with HttpClient
Spring Boot - Scheduling
Encode a String to UTF-8 in Java
An Intro to Spring Cloud Contract
@Lookup Annotation in Spring
Spring Security – security none, filters none, access permitAll
Java Program to Implement Dijkstra’s Algorithm using Queue
List Interface trong Java
Java Program to Implement the Edmond’s Algorithm for Maximum Cardinality Matching
Mapping a Dynamic JSON Object with Jackson
Apache Commons Collections Bag
Quick Guide to the Java StringTokenizer
How to Convert List to Map in Java