| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
| |
srand() must be the same as srand(1); rand();
(yet one increment)
|
|
|
|
|
|
|
| |
to compensate back at the end incremented at the start internal
state.
MFC after: 2 weeks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
but ACM formula we use have internal state (and return value) in the
[1, 0x7ffffffe] range, so our RAND_MAX (0x7fffffff) is never reached
because it is off by one, zero is not reached too.
Correct both RAND_MAX and rand(3) return value, shifting last one
to the 0 by 1 subtracted, resulting POSIXed [0, 0x7ffffffd(=new RAND_MAX)]
range.
2) Add a checks for not overflowing on too big seeds. It may happens on
the machines, where sizeof(unsigned int) > 32 bits.
Reviewed by: bde [1]
MFC after: 2 weeks
|
|
|
|
|
| |
NetBSD, OpenBSD, and Android's Bionic number the clauses 1 through 3,
so follow suit to make comparison easier.
|
|
|
|
|
|
|
|
| |
source sysctl(KERN_ARND) and remove the fallback code.
Obtained from: OpenBSD
Reviewed by: secteam
MFC after: 1 month
|
|
|
|
|
|
|
|
|
|
|
|
| |
srandomdev(). This doesn't actually work
with any modern C compiler:
In particular, both clang and modern gcc
verisons silently elide any xor operation
with 'junk'.
Approved by: secteam
MFC after: 3 days
|
|
|
|
|
|
|
|
|
| |
This fixes a race condition where another thread may fork() before CLOEXEC
is set, unintentionally passing the descriptor to the child process.
This commit only adds O_CLOEXEC flags to open() or openat() calls where no
fcntl(fd, F_SETFD, FD_CLOEXEC) follows. The separate fcntl() call still
leaves a race window so it should be fixed later.
|
| |
|
|
|
|
|
|
| |
clause.
# If I've done so improperly on a file, please let me know.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
seed->first value correlation. It breaks rand_r()... Other possible methods
like shuffling inside aray will breaks rand_r() too, because it assumes
only one word state, i.e. nothing extra can be added after seed assignment
in srand().
BTW, for old formulae seed->first value correlation is not so monotonically
increased as with other Linear Congruential Generators of this type only
becase arithmetic overflow happens. But overflow affects distribution
and lower bits very badly, as many articles says, such type of overflow
not improves PRNG.
So, monotonically increased seed->first value correlation problem remains...
|
|
|
|
| |
after srand(1)
|
|
|
|
|
|
|
| |
to remove part of seed -> 1st value correlation. Correlation still remains
because of algorithm limits. Note that old algorithm have even stronger
correlation, especially in the lower bits area, but not eye-visible, as
current one.
|
|
|
|
|
|
|
| |
at 0 as designed. Its BSD adaptation tries to fight it by mapping 0 to
2147483647 after calculation, but this method not works since 2147483647
seed returns to 0 again on the next interation. Instead of after calculation
mapping, map 0 to another value _before_ calculation, so it never stucks.
|
|
|
|
| |
may store less amount bits for seed, than available. Fix it.
|
| |
|
|
|
|
| |
I believe have made all of libc .c's as consistent as possible.
|
|
|
|
|
| |
by asking some things that need unpredictable numbers to read
/dev/random instead.
|
|
|
|
|
|
|
| |
PR: 27858
Submitted by: Yoshihiro Koya <Yoshihiro.Koya@math.yokohama-cu.ac.jp>
Reviewed by: md5(1)
Approved by: markm
|
| |
|
|
|
|
| |
change of high word part too to produce more interesting seed distribution.
|
| |
|
|
|
|
|
|
| |
Even better formula from random() could not be intetgrated because rand_r()
supposed to store its state in the single variable (but table needed for
random() algorithm integration).
|
| |
|
|
|