I am creating a game and I am currently working on the random drop system.
I plan on creating a random ID which in turn is a design for the items. If I pass the same ID twice to the createItem function it should create the exact same item.
Anyway. When I create the ID I plan on using input to be able to let some enemies drop a certain item more often. So lets say that the function looks like this for example:
void randID(int level, int diff, float wepChance, float armChance);
If I set the wepChance to 10% (0.1) when I call the function I really want it to be a 10% chance of dropping a weapon. How do I use this input together with a rand() and srand()? How does srand really work (haven’t found anything else than that is creates a seed).
I guess I could write my own code to make it really become 10% chance, but can I use srand to achieve the same result?
srandwill not help you with this.If you want a 10% chance of something occurring, then use something like the following:
This won’t be exactly 10%, because
RAND_MAXprobably doesn’t divide exactly by 10, but I imagine it’s close enough for your application.