Generating Unique Numbers

Here is sample code:

 import java.security.SecureRandom;public class UniqueNumberGenerator{    static final SecureRandom random = new SecureRandom();    static final StringBuffer buffer = new StringBuffer(30);    static    {        random.nextInt();    }    public static String getNextUID()    {        buffer.setLength(0);        Object obj = new Object();        int hash = obj.hashCode();        int rand = random.nextInt();        long time = System.currentTimeMillis() & 0xFFFFFFFF;buffer.append(Integer.toHexString(rand)).append(Long.toHexString(time)).append(Integer.toHexString(hash));        obj = null;        return buffer.toString();    }}

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: