While answeing this question I tried to run this code (for generating random numbers in a given range);
#include<stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int max_range, i = 0, rand_num;
bool digit_seen[max_range + 1]; // VLAs For C99 only
srand((unsigned)time(NULL));
printf("Enter your maximum of range: ");
scanf("%d", &max_range);
for (int i = 1; i <= max_range; i++)
digit_seen[i] = false;
for (;;)
{
rand_num = rand() % max_range + 1;
if(rand_num !=3)
if(!digit_seen[rand_num])
{
printf("%d ", rand_num);
digit_seen[rand_num] = true;
i++;
}
if( i == (max_range - 1) )
exit(0);
}
return 0;
}
It worked fine upto a max_range
of 47
but after that I got this error on debugging
Any idea why I am getting this?