I want to generate n random passwords which have 3 Uppercase letters, 3 lowercase letters and 2 numbers in it.I used this function to generate a password with 3 Uppercase letters and 3 lowercase letters and when i enter n it always shows me the same password: This is my code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
void generatepassword()
{
srand(time(NULL));
char a,b,c,d,e,f,g;
a = static_cast <char>(rand () % 26 + 65);
b = static_cast <char>(rand () % 26 + 65);
c = static_cast <char>(rand () % 26 + 65);
d = static_cast <char>(rand () % 26 + 97);
e = static_cast <char>(rand () % 26 + 97);
f = static_cast <char>(rand () % 26 + 97);
cout<<a<<b<<c<<d<<e<<f<<g<<endl;
}
int main()
{
int n;
cin>>n;
for (int i=1;i<=n;i++)
{
generatepassword();
}
return 0;
}
How can i make it show different passwords?