logo hyperPad Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Login

    How to not get the number twice with Random Value?

    Scheduled Pinned Locked Moved
    Help and Support
    4
    6
    648
    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.
    • LinkoGamesL
      LinkoGames
      last edited by

      Recently got back into HyperPad and was working on some games when I noticed the random behaviour tends to output the same number twice, or even more. Any ways to change this?

      Aidan_FireA KamdroidK 2 Replies Last reply Reply Quote 0
      • Aidan_FireA
        Aidan_Fire @LinkoGames
        last edited by Aidan_Fire

        @linkogames You mean you want to use the Random Number behaviour repeatedly, but you don't want the numbers to ever be the same as the previous number? If so, it's possible but needs some logic, I'll help you with it if I've interpreted the question right.

        1 Reply Last reply Reply Quote 0
        • Aidan_FireA
          Aidan_Fire
          last edited by

          Here's a link to my example method: http://bit.ly/2Irp5Cz
          Tried to explain it with comment behaviours the best I can.

          1 Reply Last reply Reply Quote 0
          • KamdroidK
            Kamdroid @LinkoGames
            last edited by

            @linkogames You will have to add an if statement to generate another random number if the 2nd one is the same as the 1st (though by doing this you're technically making it less random πŸ˜›)


            Or if you're ralking about something that could be a potential bug, it could be due to your behaviours being wired incorrectly or rarely a hyperPad bug,

            I just tested it right now and it works fine, so maybe it's something wrong with your behaviours, if so, give us a link to download your project that produces these strange results so we can help you,

            1 Reply Last reply Reply Quote 0
            • RobinsonXR
              RobinsonX
              last edited by

              If the two input numbers are close to each other, it will seem β€œless random.” Like 1 and 5. The chances of getting the same number twice is 1 out of 10.

              While inputs 1 and 100 will have the chances being 1 out of 200 of getting the same number twice.

              You can prevent getting a number twice by using a conditional statement:
              If it’s the same number as previously, retry.

              The argorithm will repeat itself until it has found a different number. πŸ‘Œ

              1 Reply Last reply Reply Quote 0
              • Aidan_FireA
                Aidan_Fire
                last edited by

                The retry if the number generated is the same as the previous method is a lot more simple than what I did πŸ˜‚.

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