digitalmars.empire - Empire D code question
- Clay Bridges (7/7) Dec 29 2010 I see code like this:
- Stewart Gordon (12/17) Jan 04 2011 Yes. Since 8 has only one set bit, there are only two possible values -...
I see code like this: if (ranq() & 8) ... where ranq() is defined as uint ranq() { return std.random.rand(); } Would that be a coin toss, and similar to , e.g. (ranq() & 1)? Thanks Clay
Dec 29 2010
On 29/12/2010 22:41, Clay Bridges wrote:I see code like this: if (ranq()& 8) ... where ranq() is defined as uint ranq() { return std.random.rand(); }Good question - why is this wrapper there?Would that be a coin toss, and similar to , e.g. (ranq()& 1)?Yes. Since 8 has only one set bit, there are only two possible values - 0 and 8. I don't know why 8 was chosen. I just searched the code and found instances of: ranq() & 1 (1/2 chance) ranq() & 4 (1/2 chance) ranq() & 8 (1/2 chance) ranq() & 7 (1/8 chance) ranq() & 15 (1/16 chance) Stewart.
Jan 04 2011