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:
Java – Combine Multiple Collections
Spring Boot - Cloud Configuration Server
Java Program to Compute the Volume of a Tetrahedron Using Determinants
Sử dụng Fork/Join Framework với ForkJoinPool trong Java
Java Program to Implement Binomial Tree
Java Program to Perform Left Rotation on a Binary Search Tree
Java Program to Implement Segment Tree
Hướng dẫn Java Design Pattern – Adapter
Java Program to Check Whether Topological Sorting can be Performed in a Graph
Java Program to Implement Pagoda
Java Program to Implement Find all Forward Edges in a Graph
How to Find an Element in a List with Java
Java List UnsupportedOperationException
Check If a File or Directory Exists in Java
Spring MVC Setup with Kotlin
Overview of the java.util.concurrent
Overview of Spring Boot Dev Tools
Java Program to Implement Queue using Linked List
Java Program to Implement Aho-Corasick Algorithm for String Matching
New Features in Java 10
Java Program to Implement Quick sort
Java Program to Find kth Smallest Element by the Method of Partitioning the Array
Spring Security and OpenID Connect
Jackson – JsonMappingException (No serializer found for class)
Mapping Nested Values with Jackson
Introduction to Liquibase Rollback
Documenting a Spring REST API Using OpenAPI 3.0
Copy a List to Another List in Java
Guide to PriorityBlockingQueue in Java
Base64 encoding và decoding trong Java 8
Composition, Aggregation, and Association in Java
Java – Try with Resources