Files
blog-server/src/main/java/xin/merlin/myblog_server/utils/RandomCode.java
2025-10-16 16:57:27 +08:00

21 lines
545 B
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package xin.merlin.myblog_server.utils;
import java.util.Random;
public class RandomCode {
private static final Random rand = new Random();
public static String generateID(){
// 生成一个0到999999999的随机数然后格式化为9位数字字符串
return String.format("%09d", rand.nextInt(1000000000));
}
public static String generateCode(){
// 生成一个0到999999的随机数然后格式化为6位数字字符串
return String.format("%06d", rand.nextInt(1000000));
}
}