Ifrnd: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
ifrnd: correct probabilities
Fox (talk | contribs)
No edit summary
 
Line 4: Line 4:


A <value> greater or equal to 255 corresponds to a 100% probability that the first block is taken. With a <value> of -1, the "else" block is taken every time. (A <value> of 0 means taking the "if" block once out of 256 on average).
A <value> greater or equal to 255 corresponds to a 100% probability that the first block is taken. With a <value> of -1, the "else" block is taken every time. (A <value> of 0 means taking the "if" block once out of 256 on average).
The math can be counter-intuitive, putting it simple:
* ''ifrnd 0'' will return true 1/256 of cases;
* ''ifrnd 127'' will return true 128/256 of cases;
* ''ifrnd 255'' will return true 256/256 of cases;


This command must only be used in synchronised code or you will cause desyncs. for display code use [[displayrand]] instead.
This command must only be used in synchronised code or you will cause desyncs. for display code use [[displayrand]] instead.

Latest revision as of 13:10, 11 June 2025

ifrnd <value> { do something } else { do something else }

An if condition stating the probability of it 'doin somethin!' in this case.

A <value> greater or equal to 255 corresponds to a 100% probability that the first block is taken. With a <value> of -1, the "else" block is taken every time. (A <value> of 0 means taking the "if" block once out of 256 on average).

The math can be counter-intuitive, putting it simple:

  • ifrnd 0 will return true 1/256 of cases;
  • ifrnd 127 will return true 128/256 of cases;
  • ifrnd 255 will return true 256/256 of cases;

This command must only be used in synchronised code or you will cause desyncs. for display code use displayrand instead.