All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.xiaoyuge5201.other.UuidUtils Maven / Gradle / Ivy

There is a newer version: 1.3.5
Show newest version
package com.github.xiaoyuge5201.other;

import org.apache.commons.lang3.RandomStringUtils;

import java.util.Random;
import java.util.UUID;

/**
 * 获得uuid
 * @author yugb
 */
public class UuidUtils {

	/**
	 * 获取随机盐
	 * 使用SecureRandom安全的伪随机数
	 * @param size 盐的位数
	 * @return 随机盐
	 */
	public static String getSalt(int size) {
		return RandomStringUtils.randomAlphanumeric(size);
	}
	/**
	 * 获取UUID
	 *
	 * @return UUID
	 */
	public static String getUUID() {
		return UUID.randomUUID().toString();
	}

	/**
	 * 获取不带 `-` 的UUID
	 *
	 * @return UUID
	 */
	public static String getShortUUID() {
		return getUUID().replaceAll("-", "");
	}
	/**
	 * 获取多少位的随机码
	 * @param num 位数
	 * @return 随机码
	 */
	public static String getRandomNum(Integer num){
		Random random = new Random();
		StringBuffer str = new StringBuffer();
		for (int i = 0; i < 10; i++) {
			Integer x = random.nextInt(num);
			str.append(x.toString());
		}
		return str.toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy