Create a random string or number in Qt4

前端 未结 6 581
独厮守ぢ
独厮守ぢ 2020-12-16 10:49

Is there any function or something like that by which I can create totally random strings or numbers?

6条回答
  •  情深已故
    2020-12-16 11:20

    int number;
    int randomValue = qrand() % number;
    

    returns a random number randomValue with 0 <= randomValue < number.

    qrand() is declared in QtGlobal which is #included by many other Qt files.

    int value;
    QString aString = QString::number(value);
    

    converts an integer to QString.

提交回复
热议问题