首页 > 解决方案 > 有没有办法让 randint() 更少伪且更随机?

问题描述

我正在开发一个彩票模拟器,我对 randint 生成的抽奖并不满意。

有什么技巧可以让它更随机吗?

标签: pythonrandom

解决方案


No.

This is because randint() is supposed to be pseudo-random - it, and the whole random module, has that as its entire purpose.

If you want cryptographically-secure randomness, maybe look into the secrets module instead:

The secrets module is used for generating cryptographically strong random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets.

In particularly, secrets should be used in preference to the default pseudo-random number generator in the random module, which is designed for modelling and simulation, not security or cryptography.


推荐阅读