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
Forum Updated to NodeBB v4.3 + New Features

Random number or random string with qt

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.0k 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.
  • R Offline
    R Offline
    RIVOPICO
    wrote on 23 Nov 2016, 13:48 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 23 Nov 2016, 13:58 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

      1/2

      23 Nov 2016, 13:48

      • Login

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