Random number or random string with qt



  • Hi some way to get a random number or string with Qt. I want that these elements dont repeat to get totally random strings or numbers. Any idea it's good received thx.


  • Qt Champions 2016

    Hi
    There is big difference between a random string and just a random number?
    Anyway, fast way is just

    QString MyNum;
    int rVal=rand()%1000;
    MyNum = QString::number( rVal ) ;

    If you want truly unique ID, you can use
    http://doc.qt.io/qt-5/quuid.html#details

    So solution also depends on how many you will generate and
    how unique it must be. Also over time.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.