Mercurial > hg
diff mcabber/src/jabglue.c @ 1497:35020a2ed115
Do not use srand()/rand() if better alternatives exist (mirabilos)
arc4random(3) is a self-seeding PRNG available on a lot of OSes (all BSDs,
Darwin / Mac OSX, Interix / Microsoft® Services for Unix, Windows® 2003SR1,
Windows® Vista, Debian with the new libbsd package installed, ???) and much
better than srand(3)/rand(3).
Thanks to GNU autoconf, this can be made portable.
http://www.mirbsd.org/man/arc4random.3
//mirabilos
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 30 Jun 2008 23:13:50 +0200 |
parents | 1ae5fb9b04ca |
children | 68580b6be895 |
line wrap: on
line diff
--- a/mcabber/src/jabglue.c Fri Jun 27 21:56:19 2008 +0200 +++ b/mcabber/src/jabglue.c Mon Jun 30 23:13:50 2008 +0200 @@ -567,9 +567,13 @@ static guint msg_idn; time_t now; time(&now); +#if HAVE_ARC4RANDOM + msg_idn += 1U + (unsigned int) (9.0 * (arc4random() / 4294967296.0)); +#else if (!msg_idn) srand(now); msg_idn += 1U + (unsigned int) (9.0 * (rand() / (RAND_MAX + 1.0))); +#endif return g_strdup_printf("%u%d", msg_idn, (int)(now%10L)); }