首页 > 代码库 > 随机生成手机号码

随机生成手机号码

    public static void main ( String[] args )    {               Test t = new Test();        for (int i = 0; i < 100; i++) //随机生成100个手机号码        {            System.out.println(t.getPhone());        }            }    /**     * 随机生成11位手机号码     */    public String getPhone(){                String 移动[]={"134","135","136","137","138","139","150","151","152","157","158","159","187","188"};        String 联通[]={"130","131","132","155","156","185","186","145"};         String 电信[]={"133","153","180","181","189"};         String tel[][]={移动,联通,电信};        Random rd=new Random();        int index = rd.nextInt(tel.length);//运营商个数        int size = rd.nextInt(tel[index].length); //各运营商号码个数        String phone=tel[index][size]+""+rd.nextInt(10)+""+rd.nextInt(10)+""+rd.nextInt(10)+""+rd.nextInt(10)+""+rd.nextInt(10)+""+rd.nextInt(10)+""+rd.nextInt(10)+""+rd.nextInt(10);        return phone;    }

 

随机生成手机号码