I legitimately think the problem is that pwgenerator isn't getting defined, but im' not sure why. Any ideas? On mine, when i run this to define it, pwgenerator stays blue for some reason, and it didn't before.
pwgen[length_Integer:5, num_Integer:1, similars_Boolean:1] :=
pwgenerator[length, num, similars] =
Module[{list, valid, validchars, similar, k, j, password, pwlist,
lcase, ucase, digits, spec, s}, lcase = Alphabet[];
ucase = Capitalize[lcase];
digits = Range[0, 9];
spec = StringPartition["!:#$%\'()*+,-./:;>=<?@{}[]^_|~", 1];
validchars = Flatten[Union[lcase, ucase, digits, spec]];
similar = StringPartition["Il10O5S2Z", 1];
list = {};
(* Evleything above here sets up valid keys to use for password generation *)
Table[valid = 0;
While[valid == 0,
For[j = 0; k = {};, j < length, j++,
AppendTo[k, RandomInteger[{1, Length[validchars]}]]]; (* FOR creates
random integer values between 1 and Length[validchars] *)
k = Flatten[k];
password = validchars[[k]]; (* take those elements out, and check if
there are any of the similar in the password.*)
(* If there is, and similars is 0, restart and reselect the password. If
there isn't, and similars is 1, we do the same, otherwise we accept the
password and Return it *)
Which[(Length[Intersection[password, similar]] >= 1 && similars == 0 ),
valid = 0;, (Length[Intersection[password, similar]] == 0 &&
similars == 1),
valid = 0;, (Length[Intersection[password, similar]] == 0 &&
similars == 0 ), valid = 1;
Return[password], (Length[Intersection[password, similar]] >= 1 &&
similars == 1), valid = 1; Return[password]];
], {num}];
]
Whileloop there, how often do you expect it to run before returning? Can you put inPrintorEchostatements to see if they are changing as you expect them to? – Jason B. Apr 28 '18 at 01:47Intersection[password, similar] >= 1that is problematic, sinceIntersectionis going to return a list, which isn't comparable to an integer. I think you want to useLengththere – Jason B. Apr 28 '18 at 01:49