Java Random Number createRandomHexNumber(int length)

Here you can find the source of createRandomHexNumber(int length)

Description

create Random Hex Number

License

Creative Commons License

Declaration

public static String createRandomHexNumber(int length) 

Method Source Code

//package com.java2s;
/*//from   www . j  av  a  2 s.  c  o m
 * Copyright (C) 2013 Maino
 * 
 * This work is licensed under the Creative Commons
 * Attribution-NonCommercial-NoDerivs 3.0 Unported License. To view a copy of
 * this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/ or send
 * a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
 * California, 94105, USA.
 * 
 */

import java.util.*;

public class Main {
    public static String createRandomHexNumber(int length) {
        Random random = new Random(System.currentTimeMillis());
        char[] result = new char[length];
        for (int i = 0; i < length; i++) {
            int r = random.nextInt(16);
            result[i] = Integer.toHexString(r).charAt(0);
        }
        return new String(result);
    }
}

Related

  1. createParameters(int numberOfParameters)
  2. createRandomFilename()
  3. createRandomNumber()
  4. createRandomNumber(int index)
  5. distinctInts(int from, int to, int number)
  6. generateRandomNum(int i)