Creating random numbers problem

Hi, I'm trying to make a program in c++ that will random 7 numbers every time I open the application..
I'm experiencing some problems. I need the program to make all the 7 numbers different, an they actually are sometimes, but sometimes it happens that 2 number of 7 repeats, for example:
2
4
13
18
13
19
31
- please help me if you can..

ps. here's my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main(int argc, char *argv[])
{
    int x;
         srand(time(NULL));
         rand();
        
        for (x=1;x<8;x=x+1)
    {    
       int rnd=rand() %39+1;
       cout<< rnd<<endl;
}
    system("PAUSE");
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

static bool isThereThisNumber(int number, int arr[], int size)
{
    for(int i = 0; i < size; ++i)
    {
        if(arr[i] == number)
        {
             return true;
        }
    }
    return false;
}

int main(int argc, char *argv[])
{
    const int Count = 7;
    int arr[Count] = {0};

    srand(time(NULL));

    int count = 0;        
    while(1)
    {
       if(count == Count)
       {
            break;
       }    
       int rnd=rand() %39+1;
       bool isOld = isThereThisNumber(rnd, arr, Count);
       if(isOld == true)
       {
            continue;
       }
       arr[count++] = rand;
       std::cout << rand << '\n';
    }

    return 0;
}
Last edited on
Can you even make a non member function static?
Yes -- said function is not exported from the translation unit (.cpp file), which means
it cannot be called from any other source file.
thank you for the answer :)
Topic archived. No new replies allowed.