码迷,mamicode.com
首页 > 其他好文 > 详细

Qt中使用随机数

时间:2016-04-01 23:37:52      阅读:513      评论:0      收藏:0      [点我收藏+]

标签:

新建Empty qmake project,命名为UseRand

UseRand.pro

SOURCES +=     main.cpp

QT += core

main.cpp

#include <QTime>
#include <QTextStream>

const int RAND_POS = 29;
const int DOT_SIZE = 10;

int main()
{
    QTextStream out(stdout);

    QTime time = QTime::currentTime();
    qsrand((uint) time.msec());

    int r = qrand() % RAND_POS;
    int x = (r * DOT_SIZE);

    out << RAND_POS << endl;
    out << x << endl;

    return 0;
}

 

Qt中使用随机数

标签:

原文地址:http://www.cnblogs.com/xuyan505/p/5346566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!