Don't use that code to
generate password it is insecure, acording to MS documentation:
And srand is deterministic
As code to understand some system functions the code is good but don't use for your personal passwords...
Here is some secure code to generate random password
In c you can read from /dev/urandom under linux or in windows the secure RNG like CryptGenRandom