Random with no repeats

0 favourites
  • 6 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Now I know there is already a thread on this but I kind of wanted a visual representation of it so can something tell me how to generate 4 random numbers with no 2 numbers same?

  • I threw this together quickly for you

    I use Globals to track my randoms, each on can be 1-10 (This is done by the Random1through10 Function)

    I set all values to 0 every time I run the function - clearing any old numbers

    Then I call my function 4 times to generate 4 numbers.

    One by one I set my Globals, which means if NoRepeat1 is 0 then I haven't set any and NoRepeat1 is allowed to be any random I roll

    The 2nd time the function runs NoRepeat1 wont equal 0 so it will go to the else NoRepeat2 equal 0. Now I need to verify NoRepeat2 is not the same as NoRepeat1. If it is the same I reset the value to 0 and run the function again. Which will make it to the same block and attempt again. If it's true I move on to NoRepeat3 which then checks the previous 2 in the same fashion. Last I check 4 against the previous 3.

    Obviously this will get gross when trying to do more than 4 numbers but it will work for your case and you dont have to worry about Arrays ;)

  • Thanks a lot!

  • winstreak That's super complex and extremely ineffective solution. What would you do if you need 20 random numbers?

    There is a feature called "permutation table" in the official AdvancedRandom plugin. It's pretty easy to use. Here is an example of getting 4 non-repeating numbers in the range from 1 to 10:

  • There is a feature called "permutation table" in the official AdvancedRandom plugin. It's pretty easy to use. Here is an example of getting 4 non-repeating numbers in the range from 1 to 10:

    Is it possible to use a "probability table" to get 2 non-repeating valor too?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Is it possible to use a "probability table" to get 2 non-repeating valor too?

    Of course.

    AdvancedRandom.Permutation(0) will give you the first random number.

    AdvancedRandom.Permutation(1) will give you the second random number.

    AdvancedRandom.Permutation(999) will give you the 1000th random number.

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