随机数组合,随机号码产生器

  • 来源: IT实验室 作者: sevenleaf   2010-07-20/17:55
  •       Java代码

          1.public class RandomUtil {

          2.

          3.    private static Random random = new Random();

          4.

          5.

          6.    public static String getRandomNumber(String[] range,int rangeLength,int length){

          7.        StringBuffer sb = new StringBuffer();

          8.        for(int i=0;i<length;i++){

          9.            sb.append(String.valueOf(range[random.nextInt(rangeLength)]));

          10.        }

          11.        return sb.toString();

          12.    }

          13.    public static void main(String[] args) {

          14.        String[] range = {"0","1","2","3","4","5","6","7","8","9"};

          15.        System.out.println(getRandomNumber(range, 10, 8));

          16.

          17.    }

          18.}

          运行结果:

          91373770


    评论 {{userinfo.comments}}

    {{money}}

    {{question.question}}

    A {{question.A}}
    B {{question.B}}
    C {{question.C}}
    D {{question.D}}
    提交

    驱动号 更多