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:
Sử dụng CyclicBarrier trong Java
Java Program to Implement Dijkstra’s Algorithm using Priority Queue
Java Program to Implement K Way Merge Algorithm
Java Program to Generate All Possible Combinations Out of a, b, c, d, e
Java Program to Perform Preorder Recursive Traversal of a Given Binary Tree
Sử dụng Fork/Join Framework với ForkJoinPool trong Java
Java Program to Find the Minimum Element of a Rotated Sorted Array using Binary Search approach
Comparing Long Values in Java
A Guide to the finalize Method in Java
Server-Sent Events in Spring
Introduction to Using FreeMarker in Spring MVC
Java Program to Implement Patricia Trie
Converting Between Byte Arrays and Hexadecimal Strings in Java
Encode/Decode to/from Base64
RegEx for matching Date Pattern in Java
Java 8 Collectors toMap
ETL with Spring Cloud Data Flow
Tạo ứng dụng Java RESTful Client với thư viện Retrofit
Using a Custom Spring MVC’s Handler Interceptor to Manage Sessions
A Guide To UDP In Java
A Quick Guide to Using Keycloak with Spring Boot
Tạo số và chuỗi ngẫu nhiên trong Java
Java Program to Implement RoleList API
Java Program to Implement Knapsack Algorithm
Java Program to Print only Odd Numbered Levels of a Tree
Java Program to Implement Sparse Matrix
Format ZonedDateTime to String
CharSequence vs. String in Java
How to Store Duplicate Keys in a Map in Java?
Remove the First Element from a List
Mảng (Array) trong Java
Abstract class và Interface trong Java