使用 qrand() 和 qsrand() 的唯一随机数序列 [英] Unique random number sequence using qrand() and qsrand()

查看:46
本文介绍了使用 qrand() 和 qsrand() 的唯一随机数序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在QT中生成唯一的随机数序列,使用QDateTime::currentDateTime().toTime_t()作为种子值,qrand()会生成唯一的随机数吗?

I want to generate unique random number sequence in QT, Using QDateTime::currentDateTime().toTime_t() as seed value, will qrand() generate unique random numbers?

推荐答案

没有.qrand 只能生成适合整数的唯一数字,因此——无论实现如何——你都不能指望唯一性.

No. qrand can only generate as many unique numbers as fit into an integer, so -- whatever the implementation -- you cannot count on uniqueness.

此外,知道不同的种子创建不同的随机整数会产生一定程度的可预测性,从而有效地使 qrand 不再是随机的.

Also, knowing that a different seed creates a different random integer would yield a level of predictability that effectively makes qrand not random anymore.

我发誓我不是想通过发布卡通来取笑你;我认为这是对问题的一个很好的解释:

I swear I'm not trying to make fun of you by posting a cartoon; I think this is a quite good explanation of the problem:


(来源:dilbert.com)

这篇关于使用 qrand() 和 qsrand() 的唯一随机数序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆