Create a random string or number in Qt4

前端 未结 6 563
独厮守ぢ
独厮守ぢ 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:01

    The following example generates alphabetic strings with capital letters from A to Z and length = len.

    QString randString(int len)
    {
        QString str;
        str.resize(len);
        for (int s = 0; s < len ; ++s)
            str[s] = QChar('A' + char(qrand() % ('Z' - 'A')));
    
        return str;
    }
    

提交回复
热议问题