r/ProD•
rougelikedev

Weighted random number generator for choosing tiles.

Tutorial

While messing around with the RandomSprite script to add some variation to my level generation I ran into the problem where too much variation was being added:

http://i.imgur.com/D4mgNYg.png

To fix this issue I implemented a weighted random number generator to select from the list of available tiles. The weighted random generator function was provided by one of the nice people in #unity3d on freenode.

Weighted Random Number Generator function - http://pastebin.com/7wurEHWk

RandomSprite modified to use weighted function - http://pastebin.com/rT52z97a

Script applied to a prefab - http://i.imgur.com/NHGaw0o.png

The result - http://i.imgur.com/V1OMxtG.png

Posted Oct 9, 2014, 9:00 PM UTC

83
msghmr•

Thank you for sharing this!

2
tuncOfGrayLake•

Thanks for the lovely addition, we'll think about making a similar functionality available soon. Until then this looks mighty fine!

1
tuncOfGrayLake•

Hey there!

An update on this. We're making a version of our own for this and it's coming on the next update which will happen very soon.

Thanks for the lovely suggestion.

1