Random number exclusion

0 favourites
  • 4 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • This is a real beginner's question, I think...

    How do I exclude a number from being randomly generated? Essentially, I want to save the last number generated as a variable then exclude it from the next pick so the same number is never picked twice in a row.

  • You can make a global variable called "Last_generated_number" and each time you generate a number you store it here.

    Then you can do a check:

    While

    random(number) = Last_generated_number

    Then as long the random(number) = Last_generated_number it will make a new roll.

    Then when its not Equal to the "last_generated_number" it will continue and you can use it. Then you store the new number in the "last_generated_number" variable, so it will be used for the check next time.

    If you dont used negative numbers. You can just put "Last_generated_number" to -1 as default from the beginning, so it will never match the first generated number.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I have made this with an array and choose.

    Array: 0:"0", 1:"1", 2:"2"

    than choose on the indexes and delete the picked one.

  • Thank you both! That's exactly what I needed to know.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)