• 7847阅读
  • 2回复

qrand()怎么没有定义 [复制链接]

上一主题 下一主题
离线benq
 
只看楼主 倒序阅读 楼主  发表于: 2009-04-22
《C++ GUI QT4编程(第二版)》 中第5章plotter代码    可以从http://www.informit.com/title/0132354106下载本书所以源码!
           #include <QtGlobal>
...............................................
            points0.append(QPointF(x, uint(qrand()) % 100));
            points1.append(QPointF(x, uint(qrand()) % 100));
怎么总报qrand()没有定义????

请问Qt中用那个函数产生随机数?

在Qt Assistant中找不到qrand( )的定义,也找不到qsrand( )

http://doc.trolltech.com/4.2/qtglobal.html#details 看到如下说明

int qrand ()
Thread-safe version of the standard C++ rand() function.

Returns a value between 0 and RAND_MAX (defined in <cstdlib> and <stdlib.h>), the next number in the current sequence of pseudo-random integers.

Use qsrand() to initialize the pseudo-random number generator with a seed value.

This function was introduced in Qt 4.2.
离线cnnbboy

只看该作者 1楼 发表于: 2009-04-22
int qrand ()

Thread-safe version of the standard C++ rand() function.

Returns a value between 0 and RAND_MAX (defined in <cstdlib> and <stdlib.h>), the next number in the current sequence of pseudo-random integers.

Use qsrand() to initialize the pseudo-random number generator with a seed value.

This function was introduced in Qt 4.2.

See also qsrand().

void qsrand ( uint seed )

Thread-safe version of the standard C++ srand() function.

Sets the argument seed to be used to generate a new random number sequence of pseudo random integers to be returned by qrand().

If no seed value is provided, qrand() is automatically seeded with a value of 1.

The sequence of random numbers generated is deterministic per thread. For example, if two threads call qsrand(1) and subsequently calls qrand(), the threads will get the same random number sequence.

This function was introduced in Qt 4.2.

See also qrand().
离线forwz2010
只看该作者 2楼 发表于: 2011-03-05
qrand() 和qsrand()
这有例子http://www.yafeilinux.com/?p=51
快速回复
限100 字节
 
上一个 下一个