Java高效生成6位短信验证码 疾驰 2021-04-11 2,234 阅读1分钟 低效率方法 String code = (Math.random() + "").substring(2, 8); 高效率方法 比上面块十倍的方法 String code = String.valueOf((int)((Math.random() * 9 + 1) * Math.pow(10,5))); 为什么下面的方法速度更快呢? 因为上面的方法用的了字符串截取操作,下面的方法是数值计算。 也可以说是引用类型,和基本数据类型