"rand()%anynumber" does not return "anynumber" itself e.g. 5%5 is 0.
You have to add +1
rand()%(anynumber+1)