#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
int main(void)
{
int r, a, b, line[5] = { 0 };
bool dup;
srand((unsigned)time(NULL));
printf(" POWER\n");
for (int n = 0; n < 4; n++)
{
a = 1;
b = 69;
for (int i = 0; i < 5; i++)
{
// rand() % (21) = between 0 - 20 + 10 = between 10 - 20
r = rand() % (b - a + 1) + a; // between 1 - 69
// Preventing duplicates numbers on a line
for (int j = 0; j < 5 ; j++)
{
if (line[j] != r)
dup = false;
else
{
dup = true;
break;
}
}
if (dup == false)
{
line[i] = r;
printf("%3d ", r);
}
else
i--; // start again and generate new number, instead the duplicate
}
printf(" QP - ");
a = 1;
b = 26;
for (int i = 0; i < 1; i++)
{
r = rand() % (b - a + 1) + a; // between 1 - 69
printf("%3d QP", r);
}
printf("\n");
}
return 0;
}
/*
run:
POWER
25 4 48 64 29 QP - 6 QP
51 65 1 60 19 QP - 7 QP
38 55 6 18 31 QP - 25 QP
16 28 19 47 37 QP - 24 QP
*/