Don't forget that when you use 'rand' you have to 'srand' to
initialize the random number generator:
srand (time ^ $$ | $$ << 4);
If you're really concerned about security, I would strongly
recommend something better than that, but for trivial exercises,
that should do just fine.