mercredi 2 septembre 2015

Random Generator automatically Random

As we know the following code is to Random Number

Random generator = new Random();
number = generator.nextInt(VALUE) + 1;

and i make this code to Random generator if the button click

button1 = (Button)findViewById(R.id.buttonblack);
if(v==button1) {

 // Here, we are generating a random number
 Random generator = new Random();
 number = generator.nextInt(5) + 1; 
 // The '5' is the number of values

 // Here, we are checking to see what the output of the random was
 switch(number) { 

     case 1: if(bla.. bla.. bla.. == 1){
             //Do some blaa. blaa. blaa. logic
         }
        else if(bla.. bla.. bla.. == 2){
             //Do some blaa. blaa. blaa. logic
         }
         break;
       //and so on..

My question is how to make Random Generator method is automatically Random every 2 second then increasingly faster, not by clicking a button

and how to make random stop if some button clicked, example

buttonstop = (Button)findViewById(R.id.buttonstop);    
buttonstop.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v){ 

            //Stop Random generator  

        }
     });

Anyone can Answer? Thank's




Aucun commentaire:

Enregistrer un commentaire