Correctly round towards zero in random(uint32_t)
This commit is contained in:
parent
797896e002
commit
ac601df371
1 changed files with 4 additions and 1 deletions
|
|
@ -178,7 +178,10 @@ public :
|
||||||
*/
|
*/
|
||||||
uint32_t random(uint32_t m)
|
uint32_t random(uint32_t m)
|
||||||
{
|
{
|
||||||
return uint32_t(uniform() * double(m));
|
// Make sure we always round towards zero, in order to get the
|
||||||
|
// half-open interval we want (as documented). The floor function
|
||||||
|
// does exactly this for the (always positive) values occuring here.
|
||||||
|
return uint32_t(floor(uniform() * double(m)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Biased coin toss
|
/** Biased coin toss
|
||||||
|
|
|
||||||
Reference in a new issue