Random with no repeats

Get help using Construct 3!

Post » Sat Jun 24, 2017 8:17 pm

Davioware wrote:That's not a good solution, even though it'll work in this case (since you only have 50). With larger sizes you'll endlessly hang the cpu as it regenerates and checks the numbers. What you need to do is store all your numbers in a list, (1,2 ... 500) pick a random index from the list, and return the number at that index. Then remove the number at that index from the list and repeat. This way the operation completes in a known time.


+1 to this method. It is nice and simple.

If you aren't comfortable working with arrays, you could even do this with sprites to which you have assigned a number for the instance variable:

1. Use "pick random instance", store the number assigned to that instance in an array, then delete that sprite instance.

2. Repeat until all of the instances have been destroyed.

I recommend learning how to do this with arrays though, as creating sprites for the sole purpose of destroying them is kind of wasteful.
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
48
S
14
G
24
Posts: 402
Reputation: 16,652

Post » Sun Jun 25, 2017 7:38 am

Thanks for the advice everyone, very helpful.
B
43
S
13
G
8
Posts: 622
Reputation: 7,392

Post » Mon Jun 26, 2017 2:59 pm

Image

Array is where you set your numbers, here 0-4, but you can go to as many as you like, then the sub-event goes randomly through that array and populates Array2. After each pick, selected number is removed from the first array, so there are no repeats.

Array is set to 5,1,1 to start with ( You can use push to add more numbers later )

Array2 is set to 0,1,1
B
17
S
10
G
2
Posts: 47
Reputation: 2,669

Previous

Return to How do I...?

Who is online

Users browsing this forum: No registered users and 0 guests