可生成任意指定位数的数字
public class T { /** * 随机生成 num位数字字符数组 * * @param num * @return */ public static char[] generateRandomArray(int num) { String chars = "0123456789"; char[] rands = new char[num]; for (int i = 0; i < num; i++) { int rand = (int) (Math.random() * 10); rands[i] = chars.charAt(rand); } return rands; } public static void main(String[] args) { // 随机生成6位数字 System.out.println(generateRandomArray(6)); } }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/14303.html