dimanche 9 août 2015

Reset random generator Android

i am creating an app, that in the class i have this random:

public class Ejemplo extends Activity implements OnClickListener {
 int ran=(int)(1*Math.random()) +1;

and also have this counter

int contador= 0; // this is just to know how many time i won

then i have 2 buttons a1 and a2

and in my onClick

     switch (v.getId()) {
    case R.id.a1:
        if(ran == 1){
            a1.setText("WIN");
            contador= contador + 1;
        }
        else{
            a1.setText("0");
        }
        a1.setClickable(false);
        break;

    case R.id.a2:
        if(ran == 2){
        a2.setText("WIN");
        contador= contador + 1;
        }

        else{
            a2.setText("0");
        }
        a2.setClickable(false);
        break;

so the problem is that when i press the button: New Game the random is going to have the same number of the random, and i cant just call again the activity bc i dont want to reset my counter: contador.

How i can just reset my random, so it doesnt always select the same button?




Aucun commentaire:

Enregistrer un commentaire