srand()
should be called once at the start of the program (well, at some point before you start calling rand()
anyway).
By calling it every time you enter the function (in quick succession), you're resetting the seed value to the same thing, which is why you're seeing duplicate numbers.
Note that you may occasionally get a different number if the time clicks over to a new second while your program is running, but it's not that likely since that particular program should finish in far less than one second.
Move the srand()
call to main()
before the first call to attack()
.