From 66c35ea02325d3705487f7af93ce25a0d1e5957a Mon Sep 17 00:00:00 2001 From: Ashaldsouza <116260244+Ashaldsouza@users.noreply.github.com> Date: Mon, 16 Oct 2023 18:28:33 +0530 Subject: [PATCH] Create linear_congruential_generator.java --- linear_congruential_generator.java | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 linear_congruential_generator.java diff --git a/linear_congruential_generator.java b/linear_congruential_generator.java new file mode 100644 index 0000000..7b3192f --- /dev/null +++ b/linear_congruential_generator.java @@ -0,0 +1,44 @@ +import java.util.*; +class GFG { +static void lcm(int seed, int mod, int multiplier, + int inc, int[] randomNums, + int noOfRandomNum) + { + + randomNums[0] = seed; + + + for (int i = 1; i < noOfRandomNum; i++) { + + // Follow the linear congruential method + randomNums[i] + = ((randomNums[i - 1] * multiplier) + inc) + % m; + } + } + + // Driver code + public static void main(String[] args) + { + + // Seed value + int seed = 5; + + // Modulus parameter + int mod = 7; + + // Multiplier term + int multiplier = 3; + int inc = 3;int noOfRandomNum = 10; + + // To store random numbers + int[] randomNums = new int[noOfRandomNum]; + + lcm(seed, mod, multiplier, inc, randomNums, + noOfRandomNum); + + for (int i = 0; i < noOfRandomNum; i++) { + System.out.print(randomNums[i] + " "); + } + } +}