Add comments for LoadRandomSequence

This commit is contained in:
Sergei Baigerov 2023-11-12 01:07:46 +08:00 committed by GitHub
parent 9634c84e1c
commit 680f3ac768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1727,6 +1727,7 @@ int *LoadRandomSequence(unsigned int count, int min, int max)
#else #else
if (count > (abs(max - min) + 1)) return values; if (count > (abs(max - min) + 1)) return values;
// Allocate array for putting random values into it.
values = (int *)RL_CALLOC(count, sizeof(int)); values = (int *)RL_CALLOC(count, sizeof(int));
int value = 0; int value = 0;
@ -1734,18 +1735,20 @@ int *LoadRandomSequence(unsigned int count, int min, int max)
for (int i = 0; i < count;) for (int i = 0; i < count;)
{ {
// Generate random value with max and min
value = (rand()%(abs(max - min) + 1) + min); value = (rand()%(abs(max - min) + 1) + min);
dupValue = false; dupValue = false;
for (int j = 0; j < i; j++) for (int j = 0; j < i; j++)
{ {
if (values[j] == value) if (values[j] == value) // Check for value duplication
{ {
dupValue = true; dupValue = true;
break; break;
} }
} }
// Don't add same the value
if (!dupValue) if (!dupValue)
{ {
values[i] = value; values[i] = value;