vendredi 27 février 2015

Generate random QString yields same result every time

I'm working on a QT project where a user inputs their full name and the program generates a random 5 character password based off of the letters in their name. Unfortunate I've run into an issue where it works but every time I rerun the program it yields the same result. So it clearly isn't very random. Even after exiting QT Creator and opening it again and running the program with the same user input it yields the same results.


I also am required to generate the password without spaces.


Here is my code:



while(password.length() < 5) {
int index = qrand() % fullName.length();
QChar nextChar = fullName.at(index);
if (!nextChar.isSpace()) {
password.append(nextChar);
}
}


Any solution would be much appreciated.





Aucun commentaire:

Enregistrer un commentaire