Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Random number or random string with qt

Random number or random string with qt

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • RIVOPICOR Offline
    RIVOPICOR Offline
    RIVOPICO
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved