sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Update | Sketchucation Tools 5.0.8 released with licensing improvements and bugfixes Download

    RandomBetween Not very Random

    Scheduled Pinned Locked Moved Dynamic Components
    sketchup
    7 Posts 3 Posters 1.2k 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
      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
        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
          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
            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
              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
                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
                  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

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • 1 / 1
                  • First post
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement