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. Qrand() is this just a wrapper for rand()? Does it have the same limitations?
Forum Updated to NodeBB v4.3 + New Features

Qrand() is this just a wrapper for rand()? Does it have the same limitations?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 6.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.
  • P Offline
    P Offline
    pwnstar23
    wrote on last edited by
    #1

    I couldn't find a page that talked about qrand() or sqrand() . So I'm asking here if it just wraps the functions and has same limitations?

    For example srand() and rand() will always product the same numbers given the same seed. Also it only has 0 - RAND_MAX ( which is usually around 35k)

    Which makes it a rather poor random number generator without some extra work, like building a larger value out of just the first byte of the int returned by rand. But that's another story.

    Is there any other options in QT? If not I'll just do what I said above and build larger data types out of the values returned.

    1 Reply Last reply
    0
    • U Offline
      U Offline
      uranusjr
      wrote on last edited by
      #2

      The limitations are the same. The only difference between qrand() and standard rand() is thread safety. You'll have to find some C++ lib elsewhere if you want a better random number generator. Just search the Web, there are actually quite many.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        codenode
        wrote on last edited by
        #3

        Take a look at boost::random, its header only and gives you several options for generating random numbers.

        1 Reply Last reply
        0
        • I Offline
          I Offline
          issam
          wrote on last edited by
          #4

          You want the generated random numbers to be always different ?
          You can use time function to seed random number generator and then generates the random number

          @
          srand((unsigned)time(NULL));
          int d=rand();
          cout<<d;
          @

          The time is a double edged sword :)

          http://www.iissam.com/

          1 Reply Last reply
          0

          • Login

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