JAVA生成16位唯一字符串
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(); } }
-----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------
(蓝奏云官网有些地址失效了,需要把请求地址lanzous改成lanzoux才可以)