Create a random string or number in Qt4

Create a random string or number in Qt4

Asked on January 9, 2019 in Qt.
Add Comment


  • 3 Answer(s)

    Creating a random string on qt4:

             By creating the  random numbers  by using qrand and  convert  into the string and the QUuid class  Universally Uniqand to generates the unique Identifiers. It is unique but they are totally random.

     

    Answered on January 9, 2019.
    Add Comment

    The following code is given below:

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

    By returning a random number randomValue with 0 <= randomValue < number.

       qrand() is stated in QtGlobal   in  #included by  all  other Qt files.

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

    convert by integer into Qstring.

    Answered on January 9, 2019.
    Add Comment

    The simple statement is:

    To  generate the  alphabetic strings and  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;
    }
    

     

     

    Answered on January 9, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.