0

I am having a hard time to generate 6 random numbers between 1 -25 using android studio. I would like it to be displayed in one text box. Also I don't want to get 0 and no repeats...can anyone help

This is my coding:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import java.util.Random;


public class MainActivity extends AppCompatActivity {
TextView txtrandom;
Button btnClick;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    txtrandom = (TextView) findViewById(textViewRandom);
    btnClick = (Button) findViewById(R.id.buttonClick);


    btnClick.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Random r = new Random();
            int n = r.nextInt(25) + 1;
            txtrandom.setText(String.valueOf(n));


        }
    });

    Toast.makeText(this, "Good Luck!", Toast.LENGTH_SHORT).show();


}

 /**
 * Resets the number to 0
 */
 public void resetScore(View view) {
    int textViewRandom = 0;
    displayRandom(textViewRandom);

    Toast.makeText(this, "Pick Again!", Toast.LENGTH_SHORT).show();
    return;
}

/**
 * Displays the random number.
 */
public void displayRandom(int score) {
    TextView scoreView = (TextView) findViewById(R.id.textViewRandom);
    scoreView.setText(String.valueOf(score));

}

}

  • 1
    Also: http://stackoverflow.com/questions/363681/generating-random-integers-in-a-specific-range – Andy Turner Oct 24 '16 at 12:16
  • Check this [http://stackoverflow.com/a/8115744/4217346](http://stackoverflow.com/a/8115744/4217346) – Furqan Oct 24 '16 at 12:22
  • none of these answer my question. I am new to this and I am trying to generate a 6 random numbers with one button click. I know how to generate one random number, but I want to display six at one time. – On The 9th Apps Jan 09 '17 at 15:56

0 Answers0