commit f0814f307bb304b10bf2a3603952fbf4d70b00b3 from: Sven M. Hallberg date: Wed Nov 22 23:46:54 2023 UTC stick to rand for portable This backs out commit 40c37b5c (use arc4random) except for the header include. Crappy old rand(3) is fine for this program. It's just bad form on OpenBSD and its linker spews an annoying warning about it. FWIW, Linux finally got arc4random(3) with glibc >= 2.36 (2022) so it could actually be considered fairly portable now. However, for the time being, I'd like to still support older systems. NB, the closest "native" alternative, getentropy(3), appears in glibc >= 2.25 (2017), so even it is not exactly ancient, yet. Thus, instead of mucking around with wrappers, feature flags and conditional compilation, rand() is still it for portable. commit - aba7856aa944db993d533420fa5861adfb294a7f commit + f0814f307bb304b10bf2a3603952fbf4d70b00b3 blob - 38193f39f73b7e650f94ae57f386b88611662c35 blob + 13f06ec0f1629226d9b385f8f22f39fb4faf1390 --- teach.c +++ teach.c @@ -327,6 +327,7 @@ teach(void) mistake = initmis; avgtime = initrsp; vartime = initvar; + srand(time(NULL)); puts("\n" " Type what you hear!\n" @@ -362,7 +363,7 @@ teach(void) l = 0; for (i = 0; i < nactive; i++) l += basemul * overall + failprob[i]; - x = l * ((double)arc4random() / UINT32_MAX); + x = l * rand() / RAND_MAX; assert(nactive > 1); for (i = 0; i < nactive - 1; i++) { x -= basemul * overall + failprob[i]; @@ -371,7 +372,7 @@ teach(void) } assert (i < nactive); /* avoid too many direct repeats */ - if (nactive > 2 && alphabet[i] == ch && arc4random() % 2) + if (nactive > 2 && alphabet[i] == ch && rand() <= RAND_MAX/2) continue; ch = alphabet[i];