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. SOLVED: More randomness
QtWS25 Last Chance

SOLVED: More randomness

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.6k Views
  • 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.
  • C Offline
    C Offline
    cazador7907
    wrote on last edited by
    #1

    I've set up a simple condition to generate a random number based on a seed value. The code is below. The problem is that no matter what I assign as the seed value, I keep getting the same sequence again and again.

    What am I doing wrong?

    @
    qsrand(QTime::currentTime().msec());
    returnValue = ((rand() % (m_iUpperBound - m_iLowerBound + 1)) + m_iLowerBound);
    @

    Laurence -

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cazador7907
      wrote on last edited by
      #2

      Never mind. I figured it out. Stupid error.

      Laurence -

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #3

        Let me guess, you were setting the seed every time you wanted a random number? Typically you would seed the generator once, in the constructor say.

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cazador7907
          wrote on last edited by
          #4

          Yep! That's what I did.

          Laurence -

          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