From a1b79aa278cf859c4980295df6f291375ff39c30 Mon Sep 17 00:00:00 2001
From: Joshua Colp <jcolp@digium.com>
Date: Mon, 26 Nov 2007 15:28:13 +0000
Subject: [PATCH] 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: https://origsvn.digium.com/svn/asterisk/trunk@89576 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 main/utils.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/main/utils.c b/main/utils.c
index 97abe80ae4..afddae6bf9 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
-- 
GitLab