Browse Source

Replace do-while with for-loop in GetRandomValue rejection sampling

pull/5392/head
Marcos De La Torre 2 months ago
parent
commit
216785b5af
1 changed files with 3 additions and 2 deletions
  1. +3
    -2
      src/rcore.c

+ 3
- 2
src/rcore.c View File

@ -1758,11 +1758,12 @@ int GetRandomValue(int min, int max)
unsigned long t = c - (c % m); // largest multiple of m <= c
unsigned long r;
do
for (;;)
{
r = (unsigned long)rand();
if (r < t) break; // Only accept values within the fair region
}
while (r >= t);
value = min + (int)(r % m);
}

Loading…
Cancel
Save