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 Interpolation Search Algorithm
Enum trong java
Runnable vs. Callable in Java
Functional Interfaces in Java 8
Giới thiệu luồng vào ra (I/O) trong Java
Java Program to Solve the 0-1 Knapsack Problem
Guide to the Synchronized Keyword in Java
Sorting in Java
How to Define a Spring Boot Filter?
Hướng dẫn Java Design Pattern – Mediator
Quick Guide to the Java StringTokenizer
Database Migrations with Flyway
Java Program to Perform Polygon Containment Test
Compare Two JSON Objects with Jackson
Java Program to Implement Disjoint Sets
Java Program to Implement Shell Sort
File Upload with Spring MVC
Receive email using IMAP
LinkedList trong java
Java Program to Implement the Program Used in grep/egrep/fgrep
Java Program to Implement PriorityQueue API
Guide to the Fork/Join Framework in Java
Quản lý bộ nhớ trong Java với Heap Space vs Stack
Java Program to Implement Wagner and Fisher Algorithm for online String Matching
Introduction to Apache Commons Text
Java – Write an InputStream to a File
Returning Image/Media Data with Spring MVC
Java Program to Implement Sorted Array
Java Program to implement Priority Queue
Spring Boot - Bootstrapping
OAuth2.0 and Dynamic Client Registration
Test a REST API with Java