| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package jnpf.util;
- import com.github.yitter.contract.IdGeneratorOptions;
- import com.github.yitter.idgen.YitIdHelper;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Component;
- import java.util.Random;
- /**
- * @author JNPF开发平台组
- * @version V3.1.0
- * @copyright 引迈信息技术有限公司
- * @date 2021/3/16 8:54
- */
- @Slf4j
- @Component
- public class RandomUtil {
- static {
- if(YitIdHelper.getIdGenInstance() == null){
- IdGeneratorOptions options = new IdGeneratorOptions((short) 1);
- // options.WorkerIdBitLength = 8;
- // options.SeqBitLength = 4;
- YitIdHelper.setIdGenerator(options);
- }
- }
- public static void main(String[] args) {
- System.out.println(uuId());
- }
- /**
- * 生成主键id
- *
- * @return
- */
- public static String uuId() {
- long newId = YitIdHelper.nextId();
- return newId + "";
- }
- /**
- * 生成6位数随机英文
- *
- * @return
- */
- public static String enUuId() {
- String str = "";
- for (int i = 0; i < 6; i++) {
- //你想生bai成几个字符的,du就把3改成zhi几,dao如果改成1,那就生成一个1653随机字母.
- str = str + (char) (Math.random() * 26 + 'a');
- }
- return str;
- }
- /**
- * 生成排序编码
- *
- * @return
- */
- public static Long parses() {
- Long time = 0L;
- return time;
- }
- /**
- * 生成短信验证码
- *
- * @return
- */
- public static String getRandomCode() {
- String code = "";
- Random rand = new Random();
- for (int i = 0; i < 6; i++) {
- int ran = rand.nextInt(10);
- code = code + ran;
- }
- return code;
- }
- }
|