Add srand(time(NULL)); before you use rand(). That's how I learned it, anyway.