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:
Collection trong java
Guide to the Volatile Keyword in Java
Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java
Java Program to Implement Bubble Sort
Batch Processing with Spring Cloud Data Flow
Exploring the New Spring Cloud Gateway
Upload and Display Excel Files with Spring MVC
Immutable Objects in Java
Tạo ứng dụng Java RESTful Client không sử dụng 3rd party libraries
Java Program to Perform Partition of an Integer in All Possible Ways
Java Program to Implement Strassen Algorithm
Java Program to Create a Minimal Set of All Edges Whose Addition will Convert it to a Strongly Conne...
HTTP Authentification and CGI/Servlet
Java Program to Implement the One Time Pad Algorithm
Java – String to Reader
Java Program to Implement Brent Cycle Algorithm
Annotation trong Java 8
Java Program to Implement Expression Tree
Java Program to Implement CopyOnWriteArraySet API
Java Program to Perform integer Partition for a Specific Case
Spring Boot - Enabling HTTPS
Java Program to do a Depth First Search/Traversal on a graph non-recursively
Java Program to Implement LinkedHashMap API
Java Collections Interview Questions
Java Program to implement Bit Matrix
Java Program to Find the GCD and LCM of two Numbers
Spring Boot - Hystrix
Semaphore trong Java
Lập trình mạng với java
Java NIO2 Path API
How to Change the Default Port in Spring Boot
Hướng dẫn sử dụng Java Reflection