sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    RandomBetween Not very Random

    Scheduled Pinned Locked Moved Dynamic Components
    sketchup
    7 Posts 3 Posters 930 Views 3 Watching
    Loading More Posts
    • 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.
    • ninomaydaN Offline
      ninomayda
      last edited by

      I've set up two separeate variables to generate "RandBetween(1,5)" and "OnClick" to "Redraw". When Redraw occurs, I invariably get the exact same result on BOTH RandBetween variables. I would have expected 2 different random values.

      Nino

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        Hi Nino,

        I see the same behavior. Seems like a bug in DC's.

        As an alternative, you can use something like:

        =round(rand() * 4 + 1)

        Hi

        1 Reply Last reply Reply Quote 0
        • DareDevilD Offline
          DareDevil
          last edited by

          Same with RAND()...
          If the formula is the same, the result is the same.

          But, if you add a number between the bracket, the random number will be different for each different number.

          = CEILING ( RAND(1) * 5)    (same as = ROUND ( RAND(1) * 5 + 1)
          generate different result than
          = CEILING ( RAND(2) * 5)

          @jim said:

          As an alternative, you can use something like:
          =round(rand() * 4 + 1)

          Be carrefull, this is not the same as RANDBETWEEN(1,5), giving a number in [1, 2, 3, 4,5].
          ROUND(RAND() * 4 + 1) give a number in [1, 2, 3, 4].

          RAND() give a number 0 =< X < 1
          RAND() * 4 give a number 0 =< X < 4
          RAND() * 4 + 1 give a number 1 =< X < 5

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            Here's what I did. 3 identical formulas, 3 different values between 1 and 5.

            Hi

            1 Reply Last reply Reply Quote 0
            • DareDevilD Offline
              DareDevil
              last edited by

              @daredevil said:

              Same with RAND()...
              If the formula is the same, the result is the same.

              @jim said:

              Here's what I did. 3 identical formulas, 3 different values between 1 and 5.

              I was intresded with your video : all the opposite to my experience !!
              So... I tested and tested again, and finally I understand why !!! 😄

              If you type in uppercase (RAND() or RANDBETWEEN(1,5)) or use the help to insert function (that write it in uppercase), same formulas produce same result.
              But if you write in lowercase (rand() or randbetween(1,5)) each folmula produce a different result, the random is "realy" random !

              If you use mixed case, Rand() produce same result as other Rand(), but different to RaNd() that produce same as other RaNd()...

              I used to type in uppercase in DC, but now, I will always use lowercase, like in Ruby 😆

              Thanks Jim for you exemple 👍

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by

                Hi Didier,

                Thank you for investigating further.

                I am very surprised that the difference of behavior is based on the case of the letters! Not cool.

                Hi

                1 Reply Last reply Reply Quote 0
                • ninomaydaN Offline
                  ninomayda
                  last edited by

                  @daredevil said:

                  @daredevil said:

                  Same with RAND()...
                  If the formula is the same, the result is the same.

                  @jim said:

                  Here's what I did. 3 identical formulas, 3 different values between 1 and 5.

                  I was intresded with your video : all the opposite to my experience !!
                  So... I tested and tested again, and finally I understand why !!! 😄

                  If you type in uppercase (RAND() or RANDBETWEEN(1,5)) or use the help to insert function (that write it in uppercase), same formulas produce same result.
                  But if you write in lowercase (rand() or randbetween(1,5)) each folmula produce a different result, the random is "realy" random !

                  If you use mixed case, Rand() produce same result as other Rand(), but different to RaNd() that produce same as other RaNd()...

                  I used to type in uppercase in DC, but now, I will always use lowercase, like in Ruby 😆

                  Thanks Jim for you exemple 👍

                  If anybody was going to provide an answer . . . . it was shure to be SketchUcation. THANKS.

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement