美文网首页
Qt 随机数

Qt 随机数

作者: 厝弧 | 来源:发表于2016-03-31 13:30 被阅读0次

Qt 随机数

相关函数

qsrand(unsigned seed);
qrand(); 

以上为伪随机数[1],不同在于qsrand()可以根据种子值seed的值不同,来生成不同的随机数序列。因此,可以使用当前时间作为种子,来进行模拟随机数。
示例代码:

qsrand(QTime(0,0,0).secsTo(QTime::currentTime()))

上面的代码中QDateTime::secsTo()解释如下:

  • Returns the number of seconds from this time to t. If t is earlier than this time, the number of seconds returned is negative.
  • Because QTime measures time within a day and there are 86400 seconds in a day, the result is always between -86400 and 86400.
  • secsTo() does not take into account any milliseconds.
  • Returns 0 if either time is invalid.

实际上QTime(0,0,0).secsTo(QTime::currentTime())返回的值就是从0到QTime::currentTime()的值。


  1. 条件相同的情况下,函数运行两次产生的随机序列一致。

相关文章

  • Qt 杂录

    UUID MD5 随机数 Qt5.10后推荐使用 QRandomGenerator 生成随机数,而不再推荐qran...

  • Qt 随机数

    Qt 随机数 相关函数 以上为伪随机数[1],不同在于qsrand()可以根据种子值seed的值不同,来生成不同的...

  • Qt 随机数的生成

    1、生成一定范围内的随机数

  • Fedora19 如何安装QT

    sudo yum install qt qt-devel qt-x11 qt-doc qt-demos qt-ex...

  • Qt Designer使用技巧

    编译Qt Designer 安装Qt时,选择安装源码 用Qt Creator打开C:\Qt\Qt5.5.0\5.5...

  • Qt 安装环境

    Qt 安装 1.1 QT下载地址 http://download.qt.io/archive/qt/ 1.1.1 ...

  • QT5.9+MSVC2015+OPENCV4.0.0搭建

    1.资源准备 QT Qt所有版本http://download.qt.io/archive/qt/我下载了QT5....

  • Qt5学习地址

    Qt 学习之路 2(1):序(Qt 学习之路 2(1):序) Qt 学习之路 2(2):Qt 简介(Qt 学习之路...

  • 密码学基础之伪随机数

    随机数分类 真随机数 伪随机数2.1 强伪随机数2.2 弱伪随机数 真随机数:其定义为随机样本不可重现。实际上只要...

  • QT

    vs2019下QT环境搭建 下载qt5.14 https://download.qt.io/archive/qt[...

网友评论

      本文标题:Qt 随机数

      本文链接:https://www.haomeiwen.com/subject/zipelttx.html