summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/rand.c
Commit message (Collapse)AuthorAgeFilesLines
* Style fix noted by bde@ache2013-07-041-4/+8
|
* After fixing ranges restore POSIX requirement: rand() call withoutache2013-07-041-1/+6
| | | | | srand() must be the same as srand(1); rand(); (yet one increment)
* In addition to prev. commit, for repeated rand_r(3) calls don't forgetache2013-07-031-1/+5
| | | | | | | to compensate back at the end incremented at the start internal state. MFC after: 2 weeks
* 1) POSIX requires rand(3) return values to be in the [0, RAND_MAX] range,ache2013-07-031-4/+16
| | | | | | | | | | | | | | | | 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
* Renumber clauses to reduce diffs to other versionsemaste2013-06-131-1/+1
| | | | | NetBSD, OpenBSD, and Android's Bionic number the clauses 1 through 3, so follow suit to make comparison easier.
* Replace access to /dev/random with the kernel pseudo-random numberdelphij2013-04-021-21/+12
| | | | | | | | source sysctl(KERN_ARND) and remove the fallback code. Obtained from: OpenBSD Reviewed by: secteam MFC after: 1 month
* Remove undefined behavior from sranddev() andeadler2012-10-091-2/+1
| | | | | | | | | | | | 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
* libc: Use O_CLOEXEC for various internal file descriptors.jilles2012-09-291-1/+1
| | | | | | | | | 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.
* Fix typo in the commentache2007-12-111-1/+1
|
* Per Regents of the University of Calfornia letter, remove advertisingimp2007-01-091-4/+0
| | | | | | clause. # If I've done so improperly on a file, please let me know.
* Back out "drop first N values" method of removing monotonically increasedache2003-02-171-7/+1
| | | | | | | | | | | | | | | 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...
* Since we drop NSHUFF values now, set default seed to what it becomesache2003-02-051-3/+3
| | | | after srand(1)
* For rand(3) and random(3) TYPE_0 drop NSHUFF values right after srand{om}()ache2003-02-041-1/+7
| | | | | | | 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.
* Park & Miller PRNG can be safely initialized with any value but 0 and stuckache2003-02-031-1/+4
| | | | | | | 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.
* For some combinations of variable sizes and RAND_MAX value rand_r()ache2003-02-021-2/+4
| | | | may store less amount bits for seed, than available. Fix it.
* Add missing #include "namespace.h".tjr2003-01-031-0/+1
|
* Fix the style of the SCM ID's.obrien2002-03-221-2/+2
| | | | I believe have made all of libc .c's as consistent as possible.
* Add a long-overdue nail to the deprecated /dev/urandom interfacemarkm2001-10-301-1/+1
| | | | | by asking some things that need unpredictable numbers to read /dev/random instead.
* urandom(4) -> random(4) in comments.dd2001-06-071-1/+1
| | | | | | | PR: 27858 Submitted by: Yoshihiro Koya <Yoshihiro.Koya@math.yokohama-cu.ac.jp> Reviewed by: md5(1) Approved by: markm
* Add #include "un-namespace.h"ache2001-04-231-0/+1
|
* srand*dev() fallback code: change ^getpid() to ^(getpid() << 16) to allowache2001-04-231-1/+1
| | | | change of high word part too to produce more interesting seed distribution.
* Add sranddev() since srand() is not vary much with seed, typical timeache2001-04-231-0/+34
|
* Use formula with better random distribution for rand()ache2001-02-271-0/+26
| | | | | | 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).
* Added Posix rand_r function.wes1999-05-241-1/+52
|
* BSD 4.4 Lite Lib Sourcesrgrimes1994-05-271-0/+54
OpenPOWER on IntegriCloud