Random: Exclude a number and don't repeat the rest

Get help using Construct 2

Post » Fri Aug 17, 2012 4:10 pm

Hello. I know there are some tutorials on how to get random numbers without duplicates on the forum, but these usually use arrays and look a bit complicated, I was just wondering if there may be a more simple way of doing what I need, otherwise I guess arrays will have to do.

So what I'm trying to do is to randomize 3 numbers like so:

13
6
11

But I also want to exclude a number of my choosing from the randomizing, and of course I need the 3 generated numbers to be all different.

Searching the forums I found and expression that @R0J0hound posted some months ago on another post:

choose(floor(random(5)), floor(random(0,20)))

This expression is great because in this example I can randomize the numbers between 0 and 20 without picking the number 5 (unless I'm mistaken). The problem is that the 3 numbers may be duplicates.

Any ideas? And thank you. Let me know if the explanation is not clear enought.

Oh and to generate the 3 numbers I use a "For each" condition, just in case you were wondering.Xavier2012-08-17 16:11:21
B
72
S
27
G
17
Posts: 254
Reputation: 14,971

Post » Fri Aug 17, 2012 7:38 pm

Besides the array solution found in other topics you could do it this way:
https://www.dropbox.com/s/qyhadfz1oi6o3 ... .capx?dl=1
/examples14/nonrepeating_random_from_set.capx
Last edited by R0J0hound on Mon Jun 05, 2017 5:22 pm, edited 1 time in total.
B
89
S
30
G
95
Posts: 5,159
Reputation: 63,454

Post » Sat Aug 18, 2012 12:55 pm

Thanks, it does work actually.
B
72
S
27
G
17
Posts: 254
Reputation: 14,971


Return to How do I....?

Who is online

Users browsing this forum: plinkie and 1 guest