I have the following Array :
arr= new int[][] { { 20, 0 }, { 2, 1 }, { 3, 2 }, { 1, 0 } };
I want getting randomly one lement from arr. For example : [3,2] or [20,0]
arr
[3,2]
[20,0]
I'm using the following code :
Random r=new Random(); int rd= rand.nextInt(arr.length);
You can use int[] randomPair = arr[randomNumber];. If you want to get that numbers in seperated variables, you can add int num1 = randomPair[0];int num2 = randomPair[1];
int[] randomPair = arr[randomNumber];
int num1 = randomPair[0];int num2 = randomPair[1];
1.4m articles
1.4m replys
5 comments
57.0k users