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. I don't understand QRandomGenerator.
Forum Updated to NodeBB v4.3 + New Features

I don't understand QRandomGenerator.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 493 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.
  • T Offline
    T Offline
    tsvigo
    wrote on last edited by
    #1

    How does the class generate this? I played with him - he doesn’t pay attention to boundaries. Min-max he writes min=0 max=18446744073709551615. When generating, a negative number is written through the number.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      If you need boundaries then use bounded() instead of generate().
      It will not change the min()/max() result but it returns the bounded result directly.

      BTW, mine QRandomGenerator::max() returns 4294967295 and QRandomGenerator64::max() returns 18446744073709551615.
      So if you are using QRandomGenerator64 which returns a quint64 value and assign the result to an int, then it is normal to get a negative number .

      T 1 Reply Last reply
      4
      • B Bonnie

        If you need boundaries then use bounded() instead of generate().
        It will not change the min()/max() result but it returns the bounded result directly.

        BTW, mine QRandomGenerator::max() returns 4294967295 and QRandomGenerator64::max() returns 18446744073709551615.
        So if you are using QRandomGenerator64 which returns a quint64 value and assign the result to an int, then it is normal to get a negative number .

        T Offline
        T Offline
        tsvigo
        wrote on last edited by
        #3

        @Bonnie , thank you. I understand - in my system the maximum unsigned long long integer is two times less than the maximum from the generator.

        JonBJ 1 Reply Last reply
        0
        • T tsvigo

          @Bonnie , thank you. I understand - in my system the maximum unsigned long long integer is two times less than the maximum from the generator.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @tsvigo
          Not sure quite what you mean or if there is still a question? QRandomGenerator has overloads which return quint32 or quint64 with generate[64]() and bounded(). If necessary pass your desired maximum value to bounded().

          The return values of quint32 or quint64 are not "negative", they are unsigned/positive. What you do with that and when "written through the number" is a different matter.

          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