diff mcabber/src/main.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 6b98dc22946d
children 0803c0bd8b76
line wrap: on
line diff
--- a/mcabber/src/main.c	Fri Jun 27 21:56:19 2008 +0200
+++ b/mcabber/src/main.c	Mon Jun 30 23:13:50 2008 +0200
@@ -140,12 +140,16 @@
   // in cw_set_ssl_options().
 
   if (!resource) {
+#if HAVE_ARC4RANDOM
+    dynresource = g_strdup_printf("%s.%08x", PACKAGE_NAME, arc4random());
+#else
     unsigned int tab[2];
     srand(time(NULL));
     tab[0] = (unsigned int) (0xffff * (rand() / (RAND_MAX + 1.0)));
     tab[1] = (unsigned int) (0xffff * (rand() / (RAND_MAX + 1.0)));
     dynresource = g_strdup_printf("%s.%04x%04x", PACKAGE_NAME,
                                   tab[0], tab[1]);
+#endif
     resource = dynresource;
   }