Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Apr 2024 06:49:12 GMT
From:      Vladimir Kondratyev <wulf@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 9289c1f6f151 - main - LinuxKPI: Add get_random_u32_below function
Message-ID:  <202404080649.4386nC1h032798@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=9289c1f6f1514e714b17026c50ec09282f079cba

commit 9289c1f6f1514e714b17026c50ec09282f079cba
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2024-04-08 06:47:42 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2024-04-08 06:47:42 +0000

    LinuxKPI: Add get_random_u32_below function
    
    get_random_u32_below returns a random integer in the interval [0, ceil),
    with uniform distribution.
    
    Sponsored by:   Serenity CyberSecurity, LLC
    Reviewed by:    emaste
    MFC after:      1 week
---
 sys/compat/linuxkpi/common/include/linux/random.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/random.h b/sys/compat/linuxkpi/common/include/linux/random.h
index e87d4412ea4e..808c5bc55974 100644
--- a/sys/compat/linuxkpi/common/include/linux/random.h
+++ b/sys/compat/linuxkpi/common/include/linux/random.h
@@ -96,6 +96,12 @@ get_random_u64(void)
 	return (val);
 }
 
+static inline uint32_t
+get_random_u32_below(uint32_t max)
+{
+	return (arc4random_uniform(max));
+}
+
 static __inline uint32_t
 prandom_u32(void)
 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202404080649.4386nC1h032798>