fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search

    RANDOM NUMBERS

    Questions & Answers
    3
    7
    1455
    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.
    • Zackry
      Zackry last edited by

      is there any way to generate random numbers ranging between 10 to 100

      S 1 Reply Last reply Reply Quote 0
      • M
        miro1360 last edited by miro1360

        0_1586114947964_d92844f8-b15d-4ee6-aeb3-b3ae1fc660aa-image.png

        Between trading and gambling is a very small gap, be careful.

        Zackry 1 Reply Last reply Reply Quote 1
        • Zackry
          Zackry @miro1360 last edited by

          @miro1360 thanks miro

          M 1 Reply Last reply Reply Quote 0
          • M
            miro1360 @Zackry last edited by

            @zackry I did an update

            Between trading and gambling is a very small gap, be careful.

            Zackry 1 Reply Last reply Reply Quote 0
            • Zackry
              Zackry @miro1360 last edited by Zackry

              @miro1360 absolute perfection , thanks a bunch , it works like a charm.

              1 Reply Last reply Reply Quote 1
              • S
                sidmcfarland @Zackry last edited by

                The answer given by @miro1360 is not quite correct and overly complicated. It unnecessarily checks itself and tries again whenever it generates a number outside of the 10-100 range. So why not instead update the block that generates the number so that it never generates a number outside of the 10-100 range? Also, you should not divide by 32768 because the max of MathRand() is 32767. Dividing by 32768 means you will sometimes get a value larger than 100. Additionally, this random number generating actually produces numbers 10-110, which is probably why there is a block to check if the value is within range. I feel my example is better and simpler. It also properly seeds the random number generator.
                0_1594473750244_Random.png

                1 Reply Last reply Reply Quote 0
                • M
                  miro1360 last edited by

                  @sidmcfarland said in RANDOM NUMBERS:

                  The answer given by @miro1360 is not quite correct and overly complicated. It unnecessarily checks itself and tries again whenever it generates a number outside of the 10-100 range. So why not instead update the block that generates the number so that it never generates a number outside of the 10-100 range? Also, you should not divide by 32768 because the max of MathRand() is 32767. Dividing by 32768 means you will sometimes get a value larger than 100. Additionally, this random number generating actually produces numbers 10-110, which is probably why there is a block to check if the value is within range. I feel my example is better and simpler. It also properly seeds the random number generator.
                  0_1594473750244_Random.png

                  • my example could divide by one more as the max value 32767, it will not break the code, yes I used the condition
                  • it was just a fast usable reply, sorry if it is "OVERLY" complicated :D, everything can be improved (so your example, because MathSrand) 🙂
                  • MathRand can be used alone, without MathSrand it does a self initialization with a random seed on every call, which is more random than fixing it to a tickCount which overflows every 49 days (and than repeats), ... initializing with MathSrand is good only for a recurring sequence (like for testing purposes to achieve the same result) ...

                  Between trading and gambling is a very small gap, be careful.

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post

                  Online Users

                  R
                  F
                  S
                  D

                  14
                  Online

                  146.7k
                  Users

                  22.4k
                  Topics

                  122.6k
                  Posts

                  Powered by NodeBB Forums | Contributors