How do I generate random numbers with duplicates

0 favourites
  • 3 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • I need to generate random numbers with duplicates, for example 6 numbers with three numbers x (3,3,3,5,6,1) or (6,3,1,5,1,1) both have 3 equal numbers, I read the forums and can't find anything similar. Can be 3x 2x 1x... but not 3x,3x.

    (I tried to make something reading the tutorial about making random number without duplicates, but can't make it work)

    Any help will be appreciated,


  • Generate a random number and store it in the first three cells of a 6x1x1 array. Then generate another number, check it's not the same as the previous, if so generate another (do this recursively until you get one), insert it into 4th cell. Do the same for the 5th cell. Check if cells 4 & 5 are equal, and store their value if they are. Generate the final number, checking if it is equal to the first three as above. Also, if 4 & 5 are the same, also check it's not the same as that number. Then you can 'shuffle' the array or whatever you want to do.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you!

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