62,615
社区成员
发帖
与我相关
我的任务
分享
Set<Integer> set = new HashSet<Integer>();
Random random = new Random();
while(set.size() < 10){
set.add(random.nextInt(999999));
}
Random rand = new Random();
int n = 100000+rand.nextInt(99900000);
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));
}
Set<Integer> set = new HashSet<Integer>();
Random random = new Random();
while(set.size() < 10){
float f = random.nextFloat();
Integer i = (int) (f*100000000);
set.add(i);
}
import java.util.Random;
/**
* 生成7-8位之间的随机数
*
*/
public class Test07 {
public static void main(String[] args) {
int max=10000000;
int min=1000000;
Random random = new Random();
int s = random.nextInt(max)%(max-min+1) + min;
System.out.println(s);
}
}