JAVA Program to generate random number

Hi Folks. My friend asked for a java program which can help in generating the random numbers bec...



Hi Folks. My friend asked for a java program which can help in generating the random numbers because he's writing some sort of game. Well, I'm not a big Java fan as I still love C\C++ to write codes however after writing a revolutionary code like Space Eater Virus in Java many friends suggested me to migrate from C language to Java. I left this decision on time as of now. In order to solve the problem of my buddy I randomly or you can say shamelessly got a code from internet which was written for the same purpose. Here I'm sharing that code.....

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. :) keep visiting   
Name

android facebook free-zone Freebies hacking How-to programming scripts video whatsapp
false
ltr
item
Mr Tricks: JAVA Program to generate random number
JAVA Program to generate random number
http://3.bp.blogspot.com/-ADG7RawebUs/VIzoZPUkinI/AAAAAAAAAgA/24KNDxdKOA0/s1600/3394.png
http://3.bp.blogspot.com/-ADG7RawebUs/VIzoZPUkinI/AAAAAAAAAgA/24KNDxdKOA0/s72-c/3394.png
Mr Tricks
http://mr-tricks.blogspot.com/2014/12/java-program-to-generate-random-number.html
http://mr-tricks.blogspot.com/
http://mr-tricks.blogspot.com/
http://mr-tricks.blogspot.com/2014/12/java-program-to-generate-random-number.html
true
248440411475805434
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy