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 Perform Stooge Sort
Java Program to Implement Ternary Heap
Toán tử trong java
Java Program to Permute All Letters of an Input String
Java Program to Implement Dijkstra’s Algorithm using Queue
Concatenating Strings In Java
Java Program to Implement Weight Balanced Tree
Spring 5 Functional Bean Registration
Registration – Activate a New Account by Email
Converting a Stack Trace to a String in Java
A Custom Data Binder in Spring MVC
Java Program to Perform Matrix Multiplication
Adding Shutdown Hooks for JVM Applications
Java Program to Generate All Possible Subsets with Exactly k Elements in Each Subset
Lớp Collections trong Java (Collections Utility Class)
Spring Boot Tutorial – Bootstrap a Simple Application
Build a REST API with Spring and Java Config
Lập trình đa luồng với CompletableFuture trong Java 8
Java Program to Implement Sieve Of Atkin
Java Program to Check whether Graph is a Bipartite using 2 Color Algorithm
Intro to Inversion of Control and Dependency Injection with Spring
Map to String Conversion in Java
Java Byte Array to InputStream
Java Program to Implement Sorted Array
Sao chép các phần tử của một mảng sang mảng khác như thế nào?
SOAP Web service: Upload và Download file sử dụng MTOM trong JAX-WS
Guide to the Volatile Keyword in Java
Java Program to Check Whether a Given Point is in a Given Polygon
Spring Security and OpenID Connect
Set Interface trong Java
Java Timer
How to Find an Element in a List with Java