import lombok.extern.slf4j.Slf4j; import java.util.Random; import java.util.UUID; public class RandomUtils { private static long getRandom(long n) { long min = 1, max = 9; for (int i = 1; i < n; i++) { min *= 10; max *= 10; } long rangeLong = (((long) (new Random().nextDouble() * (max - min)))) + min; return rangeLong; } /** * 生成16位唯一字符串 * @return */ public static String getUniqueId(){ String uuid = UUID.randomUUID().toString().replaceAll("-", ""); uuid=uuid.substring(0,10); StringBuilder builder=new StringBuilder(); builder.append(uuid) .append(getRandom(3)); return builder.toString(); } }
标签:JAVA,uuid,min,max,16,long,return,字符串,import From: https://www.cnblogs.com/pxblog/p/17823945.html