Too many arguments to function rand

I really am in the dark on this one. This is a function from my "zombie rabbits " program. I am trying to make a function that randomizes the chance of a baby being male female or zombie. I tried to use the same number generation code I used for a guess my number game and it's not working. Any and all help is appreciated.

The error message: In function 'void repopulate()':
82:26: error: too many arguments to function 'int rand()'
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
{
    int babies;
    babies = 1;
    while(babies != 0){
    int rabbitsex;
    srand( time(0));
    rabbitsex = rand(time)%20+1;
        switch (rabbitsex)
        {
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 7:
        case 8:
        case 9:
        case 10:
         m++;
         break;
        case 11:
        case 12:
        case 13:
        case 14:
        case 15:
        case 16:
        case 17:
        case 18:
        case 19:
         f++;
         break;
        case 20:
         z++;
         break;
        }
    babies--;
    }
}
Last edited on
http://www.cplusplus.com/reference/cstdlib/rand/

rand takes ZERO parameters and you're passing in time for some reason.
The random number generator that rand() uses has already been seeded with the current time on line 6.
rand(), as show in http://www.cplusplus.com/reference/cstdlib/rand/, takes in zero parameters and generates a random integer.

Doing int a = rand()%20; will make a be a random number in range [0, 19].
Last edited on
Thank you for the quick response. It works now. :)
Topic archived. No new replies allowed.