Random random = new Random(); double ran = Math.random(); if (ran <= 0.33) { // 6 位 System.out.println(100000 + random.nextInt(900000)); } else if ((ran > 0.33) && (ran < 0.67)) { // 7 位 System.out.println(1000000 + random.nextInt(9000000)); } else { // 8 位 System.out.println(10000000 + random.nextInt(90000000)); }
生成6位数
Random random = new Random(); System.out.println(100000 + random.nextInt(900000));
生成7位数
Random random = new Random(); System.out.println(1000000 + random.nextInt(9000000));
生成8位数
Random random = new Random(); System.out.println(10000000 + random.nextInt(90000000));