Java Random Number randomHexNumber(final int length)

Here you can find the source of randomHexNumber(final int length)

Description

random Hex Number

License

Open Source License

Declaration

public static final String randomHexNumber(final int length) 

Method Source Code

//package com.java2s;
/*/*from w w  w  .j  a  va 2 s  .c o  m*/
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

public class Main {
    /**
     * Pseudo-random number generator object for use with randomString(). The
     * Random class is not considered to be cryptographically secure, so only
     * use these random Strings for low to medium security applications.
     */
    private static Random randGen = new Random();
    private static char[] hexNumbers = "0123456789abcdef".toCharArray();

    public static final String randomHexNumber(final int length) {
        char[] randBuffer = new char[length];
        for (int i = 0; i < randBuffer.length; i++) {
            randBuffer[i] = hexNumbers[randGen.nextInt(15)];
        }
        return (new String(randBuffer));
    }
}

Related

  1. getRandonNumber(int range)
  2. getrannumber()
  3. getRndNumByLen(int lengthOfNumber)
  4. getSerialNumber(int length)
  5. getTenByteNumber()
  6. randomNumber(int length)
  7. randomNumber(int min, int max, Random r)
  8. randperm(int number)