Hutool RandomUtil
import cn.hutool.core.util.RandomUtil; import lombok.extern.slf4j.Slf4j; @Slf4j public class HutoolDemo { public static void main(String[] args) { int i = 0; String s = RandomUtil.randomString(10); //小写字母+数字 【1 => 4vhqb9qbuk】 log.info("{} => {}", ++i, s); s = RandomUtil.randomStringUpper(10); //大写字母+数字 【2 => NK5E2EW10R】 log.info("{} => {}", ++i, s); s = RandomUtil.randomNumbers(10); //数字 【3 => 9252692149】 log.info("{} => {}", ++i, s); s = RandomUtil.randomStringWithoutStr(10, "0123456789"); //不含有0123456789 【4 => knseukhoze】 log.info("{} => {}", ++i, s); s = RandomUtil.randomString("abc", 10); //只含有abc 【5 => ccbcbabaca】 log.info("{} => {}", ++i, s); char c = RandomUtil.randomChar(); // 生成小写字母+数字中一个字符 【6 => u】 log.info("{} => {}", ++i, c); c = RandomUtil.randomNumber(); // 生成0123456789中一个字符 【7 => 7】 log.info("{} => {}", ++i, c); c = RandomUtil.randomChar("-!?"); // 生成-!?中一个字符 【8 => !】 log.info("{} => {}", ++i, c); } }
有些事情,没经历过不知道原理,没失败过不明白奥妙,没痛苦过不了解真谛。临渊羡鱼,不如退而结网!

浙公网安备 33010602011771号