rand.c (d101cdd6edd782f6ec56eef63ed91abd77a8b317) rand.c (76238846ad3e9e271a3d1f792f72beab727fd153)
1/*
2 * *****************************************************************************
3 *
4 * Parts of this code are adapted from the following:
5 *
6 * PCG, A Family of Better Random Number Generators.
7 *
8 * You can find the original source code at:

--- 503 unchanged lines hidden (view full) ---

512 BC_SIG_UNLOCK;
513
514 return res;
515}
516
517BcRand
518bc_rand_bounded(BcRNG* r, BcRand bound)
519{
1/*
2 * *****************************************************************************
3 *
4 * Parts of this code are adapted from the following:
5 *
6 * PCG, A Family of Better Random Number Generators.
7 *
8 * You can find the original source code at:

--- 503 unchanged lines hidden (view full) ---

512 BC_SIG_UNLOCK;
513
514 return res;
515}
516
517BcRand
518bc_rand_bounded(BcRNG* r, BcRand bound)
519{
520 BcRand rand;
521 BcRand threshold;
522
520 // Calculate the threshold below which we have to try again.
523 // Calculate the threshold below which we have to try again.
521 BcRand rand, threshold = (0 - bound) % bound;
524 threshold = (0 - bound) % bound;
522
523 do
524 {
525 rand = bc_rand_int(r);
526 }
527 while (rand < threshold);
528
529 return rand % bound;

--- 109 unchanged lines hidden ---
525
526 do
527 {
528 rand = bc_rand_int(r);
529 }
530 while (rand < threshold);
531
532 return rand % bound;

--- 109 unchanged lines hidden ---