Stunning... the usual answer (without looking at your code) would be: "Beginner error: you forgot to call srand or you are calling srand with the same value every time before calling rand".
But, your code actually looks perfectly correct...