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:
Spring Cloud – Adding Angular
Spring Cloud AWS – EC2
Finding Max/Min of a List or Collection
Guide to @JsonFormat in Jackson
Java Perform to a 2D FFT Inplace Given a Complex 2D Array
TreeSet và sử dụng Comparable, Comparator trong java
Spring Boot - Building RESTful Web Services
A Guide to EnumMap
Entity To DTO Conversion for a Spring REST API
Overview of Spring Boot Dev Tools
Spring Boot Configuration with Jasypt
Java – Get Random Item/Element From a List
Spring Boot - Google OAuth2 Sign-In
Hướng dẫn Java Design Pattern – Flyweight
Quick Guide to @RestClientTest in Spring Boot
Java Program to Implement Min Heap
Java Program to Generate All Subsets of a Given Set in the Gray Code Order
Write/Read cookies using HTTP and Read a file from the internet
Java Program to Find the Median of two Sorted Arrays using Binary Search Approach
Apache Commons Collections BidiMap
Array to String Conversions
Inheritance and Composition (Is-a vs Has-a relationship) in Java
Guide to Character Encoding
Java Program to Perform Encoding of a Message Using Matrix Multiplication
Enum trong java
A Guide to Spring Boot Admin
Java Program to Check if a Given Set of Three Points Lie on a Single Line or Not
Spring Data MongoDB Transactions
Java Program to Describe the Representation of Graph using Adjacency List
Giới thiệu Swagger – Công cụ document cho RESTfull APIs
Logging a Reactive Sequence
Merging Two Maps with Java 8