Bitwise Operators: Difference between revisions
m
→Random Chance: Formatting consistency
Puppydrum64 (talk | contribs) m (→Random Chance: Clarification) |
Puppydrum64 (talk | contribs) m (→Random Chance: Formatting consistency) |
||
Line 40:
===Random Chance===
Given the output of a random number generator with all equally likely outcomes, you can use <code>AND</code> with that output to create random occurrences. If <math>n</math> is a power of 2, then to create a random event with probability <math>1/n</math>, you just need to <code>AND</code> the RNG output with <math>n-1</math>. In the example below, <code>rand</code> is a randomly generated number. Its size doesn't change the probabilities listed below.
<lang C>
|