id generation tool class

import java.util.Random;

/**
 * Various id generation strategies
 * <p>Title: IDUtils</p>
 * <p>Description: </p>
 * <p>Company: www.itcast.com</p>
 * @author     into the cloud dragon
 *@date Jul 22, 2015 at 2:32:10 PM
 * @version 1.0
 */
public class IDUtils {

    /**
     * Image name generation
     */ 
    public  static String genImageName() {
         // The long integer value of the current time contains milliseconds 
        long millis = System.currentTimeMillis();
         // long millis = System.nanoTime();
         // Add three random numbers 
        Random random = new Random();
         int end3 = random.nextInt(999 );
         // If there are less than three digits, add 0 in front 
        String str = millis + String.format("%03d" , end3);
        
        return str;
    }
    
    /**
     * Product id generation
     */ 
    public  static String genStringId() {
         // The long integer value of the current time contains milliseconds 
        long millis = System.currentTimeMillis();
         // long millis = System.nanoTime();
         // Add two random numbers 
        Random random = new Random();
         int end2 = random.nextInt(99 );
         // If there are less than two digits, add 0 in front 
        String id = millis + String.format("%02d" , end2);
         return id;
    }
    
    /**
     * long type id generation
     */ 
    public  static  long genLongId() {
         // The long integer value of the current time contains milliseconds 
        long millis = System.currentTimeMillis();
         // long millis = System.nanoTime();
         // Add two random numbers 
        Random random = new Random();
         int end2 = random.nextInt(99 );
         // If there are less than two digits, add 0 in front 
        String str = millis + String.format("%02d" , end2);
         long id = new Long(str) ;
         return id;
    }
    
    /*public static void main(String[] args) {
        for(int i=0;i< 100;i++)
        System.out.println (genItemId ());
    }*/
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324732098&siteId=291194637