In my game development project, I have an array of objects representing creatures. Each creature object includes a unique identifier and a corresponding weight or probability for spawning.
I am struggling to create an algorithm that will randomly spawn creatures based on their weights. I need help figuring out how to implement this feature effectively.
Could anyone provide some guidance?
Here is an example of the creatures array:
var creatures = [
{id: 1, weight: 25},
{id: 2, weight: 15},
{id: 3, weight: 5},
{id: 4, weight: 45},
{id: 5, weight: 10}
]