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

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