How do I generate Family object without duplicate?

Just started using Construct 2? Post your questions here

Post » Wed Aug 19, 2015 2:50 pm

Hi everyone,

As title stated I have 45 objects in a family and I have to generate 30 of them randomly on the map. I don't want any of the 30 to repeat though.

I tried to follow the tutorial here => https://www.scirra.com/tutorials/315/ge ... duplicates but it's still rather confusing for me. For the part where randomNumber = floor(Random(0,15)) .. how should I change it?

Thanks.
B
23
S
10
G
2
Posts: 104
Reputation: 3,071

Post » Sat Aug 29, 2015 10:56 pm

Random(0,15) generates a number from 0 to up to 15, but not 15.
With floor, he makes this random number an integer.

You could use this, with Floor(Random(45)) -> this will generate an integer between 0 and 44.
Generate 30 of these.
After that, loop through the array, and base on what the value of the array -> create your object.
Generate different object based on all the random value could be in the array
B
10
S
2
G
1
Posts: 51
Reputation: 761

Post » Tue Sep 01, 2015 3:44 pm

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Fri Sep 04, 2015 11:56 am

@RamPackWobble

Thanks :)
B
23
S
10
G
2
Posts: 104
Reputation: 3,071

Post » Sun Dec 06, 2015 6:11 am

I know this is a little late, by about 4 months or so, but I'm thinking that using a dictionary to store each random number as it's used would be a good way to check against what's still available in the random pool. Then only accept numbers that aren't already in the dictionary.
B
18
S
7
G
2
Posts: 19
Reputation: 1,863


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests