ThreadLocalRandom
在 JDK1.7 之后提供了新的类 ThreadLocalRandom 用来在并发场景下代替 Random。使用方法比较简单: public class RandomTest { public static void main(String[] args) { System.out.println(ThreadLocalRandom.current().nextInt()); System.out.println(ThreadLocalRandom.current().nextInt()); System.out.println(ThreadLocalRandom.current().nextInt(10)); } }
参考网址:https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzI0NzEyODIyOA==&scene=110#wechat_redirect