003 File Manager
Current Path:
/usr/src/sys/libkern
usr
/
src
/
sys
/
libkern
/
📁
..
📄
arc4random.c
(6.91 KB)
📄
arc4random_uniform.c
(1.78 KB)
📁
arm
📁
arm64
📄
ashldi3.c
(2.43 KB)
📄
ashrdi3.c
(2.56 KB)
📄
asprintf.c
(2.17 KB)
📄
bcd.c
(1.67 KB)
📄
bcmp.c
(4.2 KB)
📄
bcopy.c
(4.13 KB)
📄
bsearch.c
(3.07 KB)
📄
cmpdi2.c
(2.18 KB)
📄
divdi3.c
(2.2 KB)
📄
explicit_bzero.c
(512 B)
📄
ffs.c
(1.84 KB)
📄
ffsl.c
(1.85 KB)
📄
ffsll.c
(1.82 KB)
📄
fls.c
(1.84 KB)
📄
flsl.c
(1.84 KB)
📄
flsll.c
(1.85 KB)
📄
fnmatch.c
(5.89 KB)
📄
gsb_crc32.c
(42.96 KB)
📄
iconv.c
(13.11 KB)
📄
iconv_converter_if.m
(2.11 KB)
📄
iconv_ucs.c
(12.47 KB)
📄
iconv_xlat.c
(3.39 KB)
📄
iconv_xlat16.c
(8.47 KB)
📄
inet_aton.c
(3.41 KB)
📄
inet_ntoa.c
(1.8 KB)
📄
inet_ntop.c
(4.94 KB)
📄
inet_pton.c
(5.21 KB)
📄
jenkins_hash.c
(16.09 KB)
📄
lshrdi3.c
(2.24 KB)
📄
mcount.c
(8.52 KB)
📄
memcchr.c
(3.27 KB)
📄
memchr.c
(1.99 KB)
📄
memcmp.c
(2 KB)
📄
memmem.c
(2.39 KB)
📄
memset.c
(1.61 KB)
📄
moddi3.c
(2.22 KB)
📄
murmur3_32.c
(3.4 KB)
📄
qdivrem.c
(7.47 KB)
📄
qsort.c
(5.95 KB)
📄
qsort_r.c
(156 B)
📄
quad.h
(4.16 KB)
📄
random.c
(1.92 KB)
📄
scanc.c
(1.93 KB)
📄
strcasecmp.c
(2.52 KB)
📄
strcasestr.c
(2.4 KB)
📄
strcat.c
(1.83 KB)
📄
strchr.c
(1.88 KB)
📄
strchrnul.c
(1.57 KB)
📄
strcmp.c
(1.96 KB)
📄
strcpy.c
(1.82 KB)
📄
strcspn.c
(2.36 KB)
📄
strdup.c
(2.15 KB)
📄
strlcat.c
(2.56 KB)
📄
strlcpy.c
(1.64 KB)
📄
strlen.c
(3.77 KB)
📄
strncat.c
(2.23 KB)
📄
strncmp.c
(1.92 KB)
📄
strncpy.c
(2.15 KB)
📄
strndup.c
(1.98 KB)
📄
strnlen.c
(1.61 KB)
📄
strrchr.c
(1.89 KB)
📄
strsep.c
(2.63 KB)
📄
strspn.c
(2.32 KB)
📄
strstr.c
(2.11 KB)
📄
strtol.c
(4.06 KB)
📄
strtoq.c
(4.09 KB)
📄
strtoul.c
(3.13 KB)
📄
strtouq.c
(3.08 KB)
📄
strvalid.c
(2.04 KB)
📄
timingsafe_bcmp.c
(1.08 KB)
📄
ucmpdi2.c
(2.32 KB)
📄
udivdi3.c
(1.97 KB)
📄
umoddi3.c
(2 KB)
📁
x86
Editing: arc4random_uniform.c
/* $OpenBSD: arc4random_uniform.c,v 1.3 2019/01/20 02:59:07 bcook Exp $ */ /* * Copyright (c) 2008, Damien Miller <djm@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $FreeBSD$ */ #include <sys/types.h> #include <sys/libkern.h> /* * Calculate a uniformly distributed random number less than upper_bound * avoiding "modulo bias". * * Uniformity is achieved by generating new random numbers until the one * returned is outside the range [0, 2**32 % upper_bound). This * guarantees the selected random number will be inside * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound) * after reduction modulo upper_bound. */ uint32_t arc4random_uniform(uint32_t upper_bound) { uint32_t r, min; if (upper_bound < 2) return 0; /* 2**32 % x == (2**32 - x) % x */ min = -upper_bound % upper_bound; /* * This could theoretically loop forever but each retry has * p > 0.5 (worst case, usually far better) of selecting a * number inside the range we need, so it should rarely need * to re-roll. */ for (;;) { r = arc4random(); if (r >= min) break; } return r % upper_bound; }
Upload File
Create Folder