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 Decode a Message Encoded Using Playfair Cipher
Java Program to Implement CopyOnWriteArrayList API
Spring MVC Tutorial
Adding Parameters to HttpClient Requests
Java Program to Generate a Random UnDirected Graph for a Given Number of Edges
Java Program to find the number of occurrences of a given number using Binary Search approach
Java Program to Find All Pairs Shortest Path
Sử dụng JDBC API thực thi câu lệnh truy vấn dữ liệu
Spring Security 5 – OAuth2 Login
Java Program to Implement a Binary Search Tree using Linked Lists
Introduction to Spring Method Security
Practical Java Examples of the Big O Notation
Spring Boot - Runners
Java Program to Implement Weight Balanced Tree
Multi Dimensional ArrayList in Java
Read an Outlook MSG file
Guide to WeakHashMap in Java
Spring Boot - Cloud Configuration Client
Java Program to Implement Fermat Primality Test Algorithm
Removing all Nulls from a List in Java
Tạo chương trình Java đầu tiên sử dụng Eclipse
@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll
Java Program to Implement LinkedBlockingQueue API
How to Get the Last Element of a Stream in Java?
New Features in Java 12
Spring Boot Integration Testing with Embedded MongoDB
Properties with Spring and Spring Boot
Removing Elements from Java Collections
Java – Write an InputStream to a File
Lớp Collections trong Java (Collections Utility Class)
Fixing 401s with CORS Preflights and Spring Security
Hướng dẫn Java Design Pattern – Iterator