随机生成20个手机号,待完善

Posted lev1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了随机生成20个手机号,待完善相关的知识,希望对你有一定的参考价值。

 

 1 package com.homework;
 2 
 3 import java.util.HashSet;
 4 import java.util.Set;
 5 
 6 public class RandomPhone 
 7     //初始化手机前三位
 8     static String[] First = "139","138","137","136","135","134","159","158","157", 
 9             "150","151","152","188","130","131","132","156","135","133","153","189";
10     //手机号唯一 无序
11     static Set<String> phoneSet = new HashSet<String>();
12     //static Set<String> phoneSet = new HashSet<String>();
13     
14     //getNumber方法来获得数字
15     public static int getNumber(int start,int end) 
16         int sum = (int)(Math.random()*(end+1-start)+start);
17         return sum;
18     
19     public static void main(String[] args) 
20         String first = null;
21         String second = null;
22         String third = null;
23         
24         
25         
26         for(;phoneSet.size() <20;) 
27             //手机号前三位
28             int index  = getNumber(0,First.length-1);
29             first  = First[index];
30             // substring 的作用是从指定位置开始字符串
31             //生成手机剩下的8位号码
32             second = String.valueOf(getNumber(0,99999)+100000);
33             third = String.valueOf(getNumber(0,999)+1000);
34 //            second = String.valueOf(getNumber(0,99999)+100000).substring(0);
35 //            third = String.valueOf(getNumber(0,999)+1000).substring(0);
36             String ch = first+second+third;
37             phoneSet.add(ch);
38         
39         int i = 0;
40         for(String sc :phoneSet) 
41             System.out.println("第"+(++i)+"的手机号是"+sc);
42         
43     
44 

 

以上是关于随机生成20个手机号,待完善的主要内容,如果未能解决你的问题,请参考以下文章

loadrunner利用代理录制手机端实际操作中记录截图(待完善)

随机生成字符串,数字,手机号,邮箱

Python生成随机五位数——模仿手机验证码

jmeter生成随机8位手机号,进行压测登录操作,实用工具【RandomString】

Jmeter-----随机生成手机号后8位并去重,来进行注册手机号的压测

如何生成1亿个手机号码?Python生成随机数的22种方法,random函数太强了