When the user clicks a button, I am trying to fill an array with x random numbers (50,100,200...) and return them back to pass them to other class , my query is
1)How to call the random class
2)How to return the filled array from the random class to the onClick method.
public void onClick(View v) {
if(v.getId()==R.id.buttonone)
{
genrandom grandom =new genrandom();
int[] arr=new int[50];
// this array will be used as a argument for other class
public class gen_random_number {
public void genrandom(int[] arr, int x) {
Random randomGenerator = new Random();
for (int idx = 1; idx <= x; ++idx){
int randomInt = randomGenerator.nextInt(5000);
}
}
}
Thanks in advance!
create an instance of gen_random_number and call
getrandom()passing your array and x as parameters.make the return type of genrandom an
int array.