gjm
04-04-2011, 09:59 AM
(This is an erratum report for the text, not the code. It's not at all clear that it belongs here, but nowhere else seems to be more obvious. The email address info@nr.com, recommended in the book itself for submitting errata, appears not to exist any more; at least, mail sent there bounces with a "that recipient does not exist" message. Forum admins, please feel free to move this somewhere more suitable.)
Chapter 7 (Random Numbers), section 7.1 (Uniform Deviates), page 343 (below the definition of Ran) says:
If you need a random integer between 1 and n (inclusive), say, then the expression 1 + myran.int64() % (n-1) is perfectly OK (though there are faster idioms than the use of %).
No, that expression is not perfectly OK! It will produce values from 1 to n-1 inclusive. You want 1 + myran.int64() % n instead.
Chapter 7 (Random Numbers), section 7.1 (Uniform Deviates), page 343 (below the definition of Ran) says:
If you need a random integer between 1 and n (inclusive), say, then the expression 1 + myran.int64() % (n-1) is perfectly OK (though there are faster idioms than the use of %).
No, that expression is not perfectly OK! It will produce values from 1 to n-1 inclusive. You want 1 + myran.int64() % n instead.