Is there any method in java to generate random number (integer, byte or float) ?
Please tell me if any i need it in my program.
If possible please give full example.
Thanks!
Is there any method in java to generate random number (integer, byte or float) ?
Please tell me if any i need it in my program.
If possible please give full example.
Thanks!
The Random
class in the standard Java API has all you need. Just Google it.
Yes, use Java's Random class to generate random numbers like nextInt() and nextFloat(). Example:
Random random = new Random();
int randomInt = random.nextInt();
float randomFloat = random.nextFloat();
Hope this helps!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.