Share your repls and programming experiences

← Back to all posts
Java Random
Bunnytoes

Java: Random generator class

this is a java class that I can use to generate numbers easier, just add the RND.java into a file main/src/RND.java and add a package with any name and put the .class files in there add package packageName; into the RND.java file and to the main file or what file you want to use it for put import packageName.*; or import packageName.RND;.

How to use

create a RND object RND rndName = new RND(); the RND class has multiple arguments, they are all here:

once you create a RND if you put in arguments the RND you created is set to that value so you can do either System.out.println(rndName.getNext()); or int varName = rndName.getNext();
if you have no arguments you have to do rndName.next(); which provides the same argumens as the public RND (){} stuff but without the empty one so

min and max generates a random number between them min and max and Random generates a random number between them uses the Random class max generates a random number less than the max and max and Random uses the Random class to get a number less than max

I hope you enjoyed this and it was helpful

the full code is here:

Voters
prithv1
Bunnytoes