Announcement

Collapse
No announcement yet.

Manipulate RANDINT range

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts


  • Manipulate RANDINT range

    RANDINT By default, generates random number from a uniform distribution of 0 to 2,147,483,647. Is there a way to limit or manipulate this random number generation to produce numbers in the range 1000 to 5000?


  • #2
    compare what it generates and do your own math to it to keep it in range

    Comment



    • #3
      Yes. Assuming you truly want 1000 to 5000 inclusive, then use RANDREAL instead (math people use this all the time):

      MATH "TOINT(1000 + (RANDREAL() * 4001))"
      RANDREAL generates a number between 0 and 1.0, but NOT INCLUDING 1.0, so basically 0.0 to 0.999999

      You do NOT want to round, use TOINT. That way the values will be between 1000 and 5000 inclusive. If you want it to go to 4999, then just change the 4001 to 4000.
      There are 10 kinds of people in this world, those who know binary, and those who do not.

      Comment



      • #4
        Originally posted by quaizywabbit View Post
        compare what it generates and do your own math to it to keep it in range
        The Math will depend on the output and may needs to change everytime. It would be better if there a mapping function on do-more, say I want to map 0 -> 2,147,483,647 to 1000 -> 5000.
        Any suggestions?

        Comment



        • #5
          Generically speaking then, assuming Min is in V10 and Max is in V11 inclusive:

          MATH "V10 + TOINT(RANDREAL() * (1 + V11 - V10))"

          Let's assume it's emulating a die. V10 is 1, V11 is 6. If RANDREAL() is 0.9999, then the calculation will be
          1 + TOINT(0.9999 * (1 + 6 - 1)) or
          1 + TOINT(0.9999 * 6) or
          1 + TOINT(5.9994) or
          1 + 5
          or 6

          If RANDREAL() is 0.0, then the calculation will be
          1 + TOINT(0.0 * (1 + 6 - 1)) or
          1 + TOINT(0.0 * 6) or
          1 + TOINT(0.0) or
          1 + 0 or
          1

          Mathematicians do this kind of uniform random distribution all the time when doing simulations.
          Last edited by franji1; 09-05-2019, 01:07 PM.
          There are 10 kinds of people in this world, those who know binary, and those who do not.

          Comment



          • #6
            Originally posted by franji1 View Post
            Yes. Assuming you truly want 1000 to 5000 inclusive, then use RANDREAL instead (math people use this all the time):

            MATH "TOINT(1000 + (RANDREAL() * 4001))"
            RANDREAL generates a number between 0 and 1.0, but NOT INCLUDING 1.0, so basically 0.0 to 0.999999

            You do NOT want to round, use TOINT. That way the values will be between 1000 and 5000 inclusive. If you want it to go to 4999, then just change the 4001 to 4000.
            Thanks! This works

            Comment



            • #7
              Originally posted by franji1 View Post
              Generically speaking then, assuming Min is in V10 and Max is in V11 inclusive:

              MATH "V10 + TOINT(RANDREAL() * (1 + V11 - V10))"

              Let's assume it's emulating a die. V10 is 1, V11 is 6. If RANDREAL() is 0.9999, then the calculation will be
              1 + TOINT(0.9999 * (1 + 6 - 1)) or
              1 + TOINT(0.9999 * 6) or
              1 + TOINT(5.9994) or
              1 + 5
              or 6

              If RANDREAL() is 0.0, then the calculation will be
              1 + TOINT(0.0 * (1 + 6 - 1)) or
              1 + TOINT(0.0 * 6) or
              1 + TOINT(0.0) or
              1 + 0 or
              1

              Mathematicians do this kind of uniform random distribution all the time when doing simulations.
              Saw this now. Thanks for the detailed explanation.

              Comment



              • #8
                Originally posted by RockB View Post

                The Math will depend on the output and may needs to change everytime. It would be better if there a mapping function on do-more, say I want to map 0 -> 2,147,483,647 to 1000 -> 5000.
                Any suggestions?
                Not the best answer to this problem, but that's basically a SCALE.

                Comment

                Working...
                X