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 Program to Implement Levenshtein Distance Computing Algorithm
Java Program to Perform Quick Sort on Large Number of Elements
Creating a Generic Array in Java
Java Program to Find Median of Elements where Elements are Stored in 2 Different Arrays
Sử dụng CountDownLatch trong Java
Hướng dẫn sử dụng lớp Console trong java
Assert an Exception is Thrown in JUnit 4 and 5
Java Program to Implement a Binary Search Algorithm for a Specific Search Sequence
Java Program to Implement the Edmond’s Algorithm for Maximum Cardinality Matching
Spring Boot with Multiple SQL Import Files
Dynamic Proxies in Java
Checking for Empty or Blank Strings in Java
Java Program to Implement Traveling Salesman Problem using Nearest neighbour Algorithm
Java Program to Find the Median of two Sorted Arrays using Binary Search Approach
Easy Ways to Write a Java InputStream to an OutputStream
Spring Boot - Bootstrapping
Spring Security 5 – OAuth2 Login
Immutable ArrayList in Java
New Features in Java 13
Java Program to Implement Interpolation Search Algorithm
Spring Boot - Apache Kafka
Initialize a HashMap in Java
Java Program to Find Number of Articulation points in a Graph
Sorting Query Results with Spring Data
Java Program to Implement Gauss Jordan Elimination
Debugging Reactive Streams in Java
Java Program to Implement CopyOnWriteArrayList API
Java Program to Perform Searching in a 2-Dimension K-D Tree
Java Program to Implement Find all Back Edges in a Graph
Guide to Spring Cloud Kubernetes
Iterating over Enum Values in Java
Java Program to Find Minimum Number of Edges to Cut to make the Graph Disconnected