public class Random
{
private static long seed = 13;
private static long a;
private static long c;
private static long m;
public static void random_init(long s) {
if (s != 0) seed = s;
}
public static long random() {
seed = (a*seed + c)%m;
return seed;
}
public static void main(String[] args) {
if (args.length != 4) {
System.out.println("usage: you must enter values for a, c, m, seed");
return;
}
a = Long.parseLong(args[0]);
c = Long.parseLong(args[1]);
m = Long.parseLong(args[2]);
long s = Long.parseLong(args[3]);
random_init(s);
for (int k = 0; k < m-1; k++) {
System.out.println(random());
if (k % 8 == 7) { // after 8 elements go to a new line
System.out.println();
try {
Thread.sleep(1000); // sleep for a second
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}
}
If you're having troubles in compiling the code then take a look at How to Compile the JAVA Program.Keep Coding. :)
ConversionConversion EmoticonEmoticon