jeudi 18 août 2016

Logic behind generating random upper and lower case letter

I'm trying to generate an array of both upper and lower case letters at the same time.

I do understand the logic behind generating two seperate cases of letters.

rand() % 26 + 65 // generate all the uppercase letter

while

rand() % 26 + 97 // generate all the lowercase letter

I tried googling how to generate both of them together and here is what i got.

rand() % 26 + 65 + rand() % 2 * 32 // generate both upper and lowercase letter

Unfortunately, they did not exactly explain the logic behind it and i do not wish to just blindly copy and paste it into my assignment. Been searching high and low for the logic behind the rand() % 2 * 32 when adding the second rand() into the first rand().

Any help will be appreciated.




Aucun commentaire:

Enregistrer un commentaire