Random Number Generator Without Repetition Class In Java
First of all, I'm a newbie Android App developer. In my App I need a class which generates random numbers in a given range avoiding repetition. I've searched much for this issue, b
Solution 1:
I guess this line is issue.
intindex = size * (int) Math.random();
This evaluates to Zero always.
Edit:
Just consolidating comments from Jeroen Vannevel and OP.
Math.random() will return a value between 0.0 and 1.0, which when cast with (int)
will always evaluates to ZERO. You ca use as below.
intindex = (int) (size * Math.random());
Solution 2:
You should try using Random
class:
http://developer.android.com/reference/java/util/Random.html
Randomrandom=newRandom();
intrandomNo= random.nextInt(10); // 0 to 9
Post a Comment for "Random Number Generator Without Repetition Class In Java"