From a62196fc159469c946becdd107d6810ce2139650 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 7 Dec 2020 23:09:40 -0600 Subject: Rename randbuf and hook up -s --- toys/other/pwgen.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'toys/other') diff --git a/toys/other/pwgen.c b/toys/other/pwgen.c index e808ccf8..c6621ccd 100644 --- a/toys/other/pwgen.c +++ b/toys/other/pwgen.c @@ -38,7 +38,7 @@ void pwgen_main(void) { int length = 8, count, ii, jj, c, rand = 0, x = 0; unsigned xx = 80, yy = 24; - char janice[16]; + char randbuf[16]; if (isatty(1)) terminal_size(&xx, &yy); else toys.optflags |= FLAG_1; @@ -51,18 +51,19 @@ void pwgen_main(void) for (jj = 0; jj102 less likely + if (!rand) xgetrandom(randbuf, rand = sizeof(randbuf), 0); + c = 33+randbuf[--rand]%93; // remainder 69 makes >102 less likely + if (FLAG(s)) randbuf[rand] = 0; if (c>='A' && c<='Z') { if (FLAG(A)) continue; // take out half the capital letters to be more human readable - else c |= (0x80&janice[rand])>>2; + else c |= (0x80&randbuf[rand])>>2; } if (FLAG(0) && c>='0' && c<='9') continue; if (FLAG(B) && strchr("0O1lI'`.,", c)) continue; if (FLAG(v) && strchr("aeiou", tolower(c))) continue; - if (!FLAG(y) || (0x80&janice[rand])) + if (!FLAG(y) || (0x80&randbuf[rand])) if (c<'0' || (c>'9' && c<'A') || (c>'Z' && c<'a') || c>'z') continue; if (TT.r && strchr(TT.r, c)) continue; -- cgit v1.2.3