how to generate random number from array
How to generate random number from an array? and not from a range.
int n [] = {1,7,3,5,8,10,33开发者_开发问答,12,18}
import java.util.Random;
...
Random random = new Random();
System.out.println(n[random.nextInt(n.length)]);
In general terms, get a random integer ranging from a minimum of 0 to a maximum of the array length -1, and use that as the array index.
精彩评论