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:
Truyền giá trị và tham chiếu trong java
Multipart Upload with HttpClient 4
Java – InputStream to Reader
Zipping Collections in Java
Apache Commons Collections OrderedMap
Java Program to Find Location of a Point Placed in Three Dimensions Using K-D Trees
Java Byte Array to InputStream
Converting Between Byte Arrays and Hexadecimal Strings in Java
Hướng dẫn sử dụng lớp Console trong java
Giới thiệu Aspect Oriented Programming (AOP)
Check If a File or Directory Exists in Java
Generating Random Numbers in a Range in Java
Spring Boot - Service Components
Java Program to Implement Johnson’s Algorithm
Java 8 Stream findFirst() vs. findAny()
Spring Security Custom AuthenticationFailureHandler
Hướng dẫn Java Design Pattern – Iterator
How to Get a Name of a Method Being Executed?
Introduction to Spring MVC HandlerInterceptor
Java Program to Implement Strassen Algorithm
Getting Started with Custom Deserialization in Jackson
Spring Security 5 – OAuth2 Login
Java Program to Implement Double Ended Queue
Spring REST API + OAuth2 + Angular (using the Spring Security OAuth legacy stack)
Wiring in Spring: @Autowired, @Resource and @Inject
Java Program to Implement Queue using Linked List
Hướng dẫn Java Design Pattern – Strategy
Java – String to Reader
Java Program to Find Inverse of a Matrix
Using a Spring Cloud App Starter
Extract network card address
Collect a Java Stream to an Immutable Collection