Hello.
Iam having a problem with the Random()
everything gets random except for cards[0][0] that always ends up with
= 5
here is the code that i use, anyone have a solution?
in the code ROW_COUNT = 3 and COL_COUNT = 4
private void loadCards(){
try{
int size = ROW_COUNT*COL_COUNT;
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i=0;i<size;i++){
list.add(new Integer(i));
}
Random r = new Random();
for(int i=size-1;i>=0;i--){
int t=0;
if(i>0){
t = r.nextInt(i);
}
t=list.remove(t).intValue();
cards[i%COL_COUNT][i/COL_COUNT]=t%(size/2);
}
}
catch (Exception e) {
Log.e("loadCards()", e+"");
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en