How do I make a randomizer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I make a randomizer

how do make one i want one for live streams

28th Feb 2017, 8:46 PM
fireface47347 aj
fireface47347 aj - avatar
3 Answers
+ 2
there is a function in the math class called random, but it only gives a random floating point number between 0 and 1. You can call it like this: double randNum = Math.random(); You can then multiply it by any integer to increase the range: double randNum = Math.random() * 10; // random number 0 to 10 Then cast it to an int if you want a whole number: int randNum = (int)(Math.random() * 10);
28th Feb 2017, 9:16 PM
Zeke Williams
Zeke Williams - avatar
+ 2
Random r = new Random(); int number=r.nextInt(5); System.out.println(number);
28th Feb 2017, 9:31 PM
LordHill
LordHill - avatar
0
use random class
28th Feb 2017, 8:56 PM
Meharban Singh
Meharban Singh - avatar