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:
Spring Cloud AWS – S3
A Guide to the Java ExecutorService
Java Program to Implement LinkedList API
Binary Numbers in Java
Deploy a Spring Boot App to Azure
Spring Boot - Enabling HTTPS
Object Type Casting in Java
Java Program to Implement Binomial Tree
Getting Started with GraphQL and Spring Boot
ArrayList trong java
Java Program to Generate a Random UnDirected Graph for a Given Number of Edges
Tạo ứng dụng Java RESTful Client với thư viện OkHttp
Hướng dẫn sử dụng Java Annotation
Java Program to Perform Quick Sort on Large Number of Elements
Java Program to Implement Quick Hull Algorithm to Find Convex Hull
A Custom Data Binder in Spring MVC
How to Count Duplicate Elements in Arraylist
Lớp LinkedHashMap trong Java
Java Program to Find Path Between Two Nodes in a Graph
Vector trong Java
Java Program to Print the Kind of Rotation the AVL Tree is Undergoing
Guide to Java Instrumentation
JUnit 5 for Kotlin Developers
Java Program to Check if a Given Set of Three Points Lie on a Single Line or Not
Java Program to Implement Stein GCD Algorithm
So sánh Array và ArrayList trong Java
Java Program to Test Using DFS Whether a Directed Graph is Strongly Connected or Not
Transaction Propagation and Isolation in Spring @Transactional
Guide to the Volatile Keyword in Java
Java Program to Check Whether Graph is DAG
The Thread.join() Method in Java
Java Program to Implement Booth Algorithm