Java Random Number getrannumber()

Here you can find the source of getrannumber()

Description

getrannumber

License

Open Source License

Declaration

public static String getrannumber() 

Method Source Code

//package com.java2s;
// LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,

import java.util.Random;

public class Main {
    public static String getrannumber() {
        StringBuffer strbufguess = new StringBuffer();
        String strguess = new String();
        int[] nums = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        Random rannum = new Random();
        int count;
        int i = 0, temp_i = 0;
        for (int j = 10; j > 4; j--) {
            i = 0;//from   ww w. j av a  2s  . c  om
            temp_i = 0;
            count = rannum.nextInt(j);
            while (i <= count) {
                if (nums[temp_i] == -1) {
                    temp_i++;
                } else {
                    i++;
                    temp_i++;
                }
            }
            strbufguess.append(Integer.toString(nums[temp_i - 1]));
            nums[temp_i - 1] = -1;
        }
        strguess = strbufguess.toString();
        rannum = null;
        strbufguess = null;
        nums = null;
        return strguess;
    }
}

Related

  1. getRandomNumberString(int length)
  2. getRandomNumer(int length)
  3. getRandomNumericString(int maxlen)
  4. getRandomPortNumber()
  5. getRandonNumber(int range)
  6. getRndNumByLen(int lengthOfNumber)
  7. getSerialNumber(int length)
  8. getTenByteNumber()
  9. randomHexNumber(final int length)