#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Weighted Random selection with dynamic adjustment with just 8 behaviors.

Posts: 2,769Member, PRO

What is it good for?

Imagine you want waves of enemies, randomly spawned ...

... but you would like to start with more of the easy monsters in the beginning,
then as the level progresses, increase the frequency of tougher enemies.

Or simply define the type and frequency of enemies per level.

(Project attached)

• London, UK.Posts: 12,821Member
edited May 2017

Amazing stuff !! Thanks for sharing !!

P.S love the interface too !!!

• Posts: 4,590Member, PRO

Love it! Can't wait to take some time to dig in to exactly how it works!

• FREELANCE GS DEV Posts: 1,536Member

Great work Roland!

• Posts: 9,008Member, Sous Chef, PRO, Bowlboy Sidekick

Very cool and very handy! Thank you so much for sharing!

• Posts: 2,786Member, Sous Chef, PRO

This is great! Thanks for sharing with the community!

• Posts: 2,769Member, PRO

Thanks for the comments @Socks, @Armelline, @gingagaming, @Braydon_SFX, @RThurman !

@Armelline said:
Can't wait to take some time to dig in to exactly how it works!

After messing about, the simplicity surprised me:

Make a table with enemies, adding the desired ratio each should appear. The order does not matter.

Now pick a random value from the sum of the ratios.

Then loop over the enemy table, subtracting each ratio from your random number until you reach 0 or less. The previous enemy is then the one to spawn.

• London, UK.Posts: 12,821Member

@Hopscotch said:
After messing about, the simplicity surprised me:

Things are always 'simple' once you've worked out the answer.

@Hopscotch said:
Now pick a random value from the sum of the ratios.

Then loop over the enemy table, subtracting each ratio from your random number until you reach 0 or less. The previous enemy is then the one to spawn.

Oh yeah, that was really obvious, I'm surprised you even had to work it out

• Encounter Bay, South AustraliaPosts: 1,358Member, BASIC

@Hopscotch Snippets of brilliance like this inspire me with some great ideas that I would never attempt on my own without your tutelage. Once again, thank you.

• Posts: 2,769Member, PRO

@Socks Well, yeah, things always get lost in translation somewhere between my brain and mouth, I blame it on a sinus condition.

My pleasure @PhilipCC