How do I generate random numbers with duplicates

Get help using Construct 2

Post » Sun Jan 18, 2015 1:03 am

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,
Thanks.
B
23
S
6
G
2
Posts: 22
Reputation: 1,996

Post » Sun Jan 18, 2015 1:30 am

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.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Sun Jan 18, 2015 2:21 am

Thank you!
B
23
S
6
G
2
Posts: 22
Reputation: 1,996


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests