This is java program to generate the random numbers, using the Park-Miller algorithm.Park–Miller random number generator (after Stephen K. Park and Keith W. Miller), is a variant of linear congruential generator (LCG) that operates in multiplicative group of integers modulo n. A general formula of a random number generator (RNG) of this type is, x(n+1) = g*x(n) mod n.
Here is the source code of the Java Program to Implement Park-Miller Random Number Generation Algorithm. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
//This is a sample program to random numbers using Park Miller Random Numbers algorithm public class Park_Miller_Random_Numbers { static final long m = 2147483647L; static final long a = 48271L; static final long q = 44488L; static final long r = 3399L; static long r_seed = 12345678L; public static double uniform () { long hi = r_seed / q; long lo = r_seed - q * hi; long t = a * lo - r * hi; if (t > 0) r_seed = t; else r_seed = t + m; return r_seed; } public static void main (String[] argv) { double[] A = new double [10]; for (int i=0; i<5; i++) A[i] = uniform(); for (int i=0; i<5; i++) System.out.print (" " + A[i]); } }
Output:
$ javac Park_Miller_Random_Numbers.java $ java Park_Miller_Random_Numbers 1.085252519E9 5.08259731E8 1.352291773E9 1.563240271E9 8.90733155E8 ...
Related posts:
Phương thức forEach() trong java 8
Kruskal's Algorithm
Java Program to Implement Affine Cipher
Java Program to Repeatedly Search the Same Text (such as Bible by building a Data Structure)
Injecting Prototype Beans into a Singleton Instance in Spring
Java Program to Implement Skip List
Finding the Differences Between Two Lists in Java
Hướng dẫn Java Design Pattern – Factory Method
Spring Boot - Build Systems
Testing in Spring Boot
Concurrent Test Execution in Spring 5
Spring Boot - Introduction
Java Program to Implement Bresenham Line Algorithm
Hướng dẫn sử dụng Printing Service trong Java
Send an email using the SMTP protocol
Java Program to Implement Quick Hull Algorithm to Find Convex Hull
Java Program to Implement the RSA Algorithm
Java Program to Check if a Given Set of Three Points Lie on a Single Line or Not
Lớp lồng nhau trong java (Java inner class)
Guide to Guava Table
How to Count Duplicate Elements in Arraylist
Configure a Spring Boot Web Application
How to Break from Java Stream forEach
Giới thiệu Java Service Provider Interface (SPI) – Tạo các ứng dụng Java dễ mở rộng
Spring REST API + OAuth2 + Angular
Spring Cloud Bus
Java Program to Check Cycle in a Graph using Topological Sort
Sorting Query Results with Spring Data
Java Program to Compare Binary and Sequential Search
Java Program to Implement Floyd Cycle Algorithm
Java Program to Implement Sorted Array
Encode/Decode to/from Base64