aboutsummaryrefslogtreecommitdiffstats
path: root/main/utils.c
diff options
context:
space:
mode:
authorfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2007-11-26 15:28:13 +0000
committerfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2007-11-26 15:28:13 +0000
commit5219dc885e2fda7239653750aa800e4de6375d39 (patch)
tree72aefaffbc3bc04d877e864d260da23144866375 /main/utils.c
parentd7b36511c063774a54a88c23785497ca3b823e6f (diff)
Make the behavior of using /dev/urandom for random numbers the same as random().
(closes issue #11348) Reported by: sperreault Patches: ast_random2.diff uploaded by sperreault (license 252) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@89576 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/utils.c')
-rw-r--r--main/utils.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/main/utils.c b/main/utils.c
index 97abe80ae..afddae6bf 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -1138,8 +1138,10 @@ long int ast_random(void)
#ifdef HAVE_DEV_URANDOM
if (dev_urandom_fd >= 0) {
int read_res = read(dev_urandom_fd, &res, sizeof(res));
- if (read_res > 0)
- return res < 0 ? ~res : res;
+ if (read_res > 0) {
+ res = res < 0 ? ~res : res;
+ return res % ((long)RAND_MAX + 1);
+ }
}
#endif
#ifdef linux