Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
1496:b9f8c1fddb23 | 1497:35020a2ed115 |
---|---|
565 static char *new_msgid(void) | 565 static char *new_msgid(void) |
566 { | 566 { |
567 static guint msg_idn; | 567 static guint msg_idn; |
568 time_t now; | 568 time_t now; |
569 time(&now); | 569 time(&now); |
570 #if HAVE_ARC4RANDOM | |
571 msg_idn += 1U + (unsigned int) (9.0 * (arc4random() / 4294967296.0)); | |
572 #else | |
570 if (!msg_idn) | 573 if (!msg_idn) |
571 srand(now); | 574 srand(now); |
572 msg_idn += 1U + (unsigned int) (9.0 * (rand() / (RAND_MAX + 1.0))); | 575 msg_idn += 1U + (unsigned int) (9.0 * (rand() / (RAND_MAX + 1.0))); |
576 #endif | |
573 return g_strdup_printf("%u%d", msg_idn, (int)(now%10L)); | 577 return g_strdup_printf("%u%d", msg_idn, (int)(now%10L)); |
574 } | 578 } |
575 | 579 |
576 // jb_send_msg(jid, text, type, subject, msgid, *encrypted, type_overwrite) | 580 // jb_send_msg(jid, text, type, subject, msgid, *encrypted, type_overwrite) |
577 // When encrypted is not NULL, the function set *encrypted to 1 if the | 581 // When encrypted is not NULL, the function set *encrypted to 1 if the |