0
how to get a specific type of random number
what if i want to get a random number which only has 6 digits or any number of digits i want to specify. it would be great if u guys help me by just explaining how to solve and not specifically by giving codes. i would appreciate ur help.
1 Answer
+ 1
you can use this func to generate random numbers with specific digits
import static java.lang.Math.pow;
import java.util.Random;
int randGen(int digits){
int results = 0;
Random rand = new Random();
for(int i = 1;i<=digits;i++){
results+= pow(10,i)*rand.nextInt(10)//min is 0 max is 9
}
return results;
}