Random类导致抢红包接口出现严重性能问题

生成随机数是一个常见的功能,例如我们给用户生成随机红包。但是你知道java.util.Random类在高并发的情况下具有性能问题和安全问题吗?我们在高并发常见下应该如何生成随机数呢?

要知道为什么java.util.Random类具有性能问题,得深入到其中是实现来探究一下。

首先看一下Random类的doc说明

An instance of this class is used to generate a stream of pseudorandom numbers. The class uses a 48-bit seed, which is modified using a linear congruential formula.

If two instances of Random are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers

Random类的实例可以用来生成一个“伪随机”数字流。这个类使用48bit的种子,并且使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

高级Java进阶之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值