Random of min max values

Started by
10 comments, last by nobodynews 16 years, 11 months ago
Think ill cover the entire random area :)
Hope this is the last question i have in that topic...

how do you randomize your event with percentages?
for a certain event, Event #1 will have 90 percent for been triggered
and Event #2 will have 10 percent for been triggered...?
Advertisement
You're starting to get into the concept of probability distributions. What you've been mucking around in is the uniform distribution where every event has an equal chance of occuring.

I think the easiest way is to define each event having a Range of values. If you have two events where one event is 90% and the other 10%, then you can get a random number between 0 and 9 and then the numbers between 0 and 8 are event one, and 9 is event 2. This can be generalized for larger numbers of events.

Of course, if you use modulo then your distribution will in fact be different because, say, rand() % 10 is NOT evenly distributed. That is, some numbers will occur more often than others. This will end up skewing the ranges given above.

Hope this helps.

edit: I should probably mention solutions around using % for getting your random numbers instead of just saying it will cause problems. This site seems pretty good at explaining techniques to get a better distribution.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

This topic is closed to new replies.

Advertisement