tytso / pwgen

Automatic Password generation
83 stars 18 forks source link

Modulo Bias #7

Open stone14z opened 3 years ago

stone14z commented 3 years ago

pw_random_number(max_num) simply performs a modulo of a random integer against the number of elements in the character array. Since there is no check whether the maximum integer value is divisible by the number of elements in the character array, modulo bias is introduced. This would need to be fixed before the command is used to generate passwords for a high security environment.

stone14z commented 3 years ago

The pw_random_number function can be re-written as follows to remove the modulo bias

/*