[Freeswitch-dev] switch_stun_random_string returns identical strings on two calls randomly
Seven Du
dujinfang at gmail.com
Tue Jan 31 12:51:26 MSK 2012
Hi,
I tried to replace the following function which I copied somewhere in msrp.c with switch_stun_random_string (http://docs.freeswitch.org/group__stun1.html#geb124530a232d65edc508afd1b9dd615) but I found sometimes switch_stun_random_string (http://docs.freeswitch.org/group__stun1.html#geb124530a232d65edc508afd1b9dd615) returns identical strings on two sequential calls, with the following function I never found, so I still use it.
By looking the code I understand srand seed is time based so it's possible to return duplicate random string, but I found switch_stun_random_string (http://docs.freeswitch.org/group__stun1.html#geb124530a232d65edc508afd1b9dd615) used in some places other than stun, just curious would it cause problems?
void random_string(char *buf, switch_size_t size)
{
long val[4];
int x;
for (x = 0; x < 4; x++)
val[x] = random();
snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]);
*(buf+size) = '\0';
}
Thanks.
--
About: http://about.me/dujinfang
Blog: http://www.dujinfang.com
Proj: http://www.freeswitch.org.cn
Sent with Sparrow (http://www.sparrowmailapp.com)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-dev/attachments/20120131/77e67164/attachment.html
Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-dev
mailing list