Home
last modified time | relevance | path

Searched hist:"476 d9314d6247b8386926960081689e8f395594c" (Results 1 – 2 of 2) sorted by relevance

/freebsd/lib/libc/stdlib/
H A Drand.cdiff 476d9314d6247b8386926960081689e8f395594c Wed Jul 03 23:21:54 CEST 2013 Andrey A. Chernov <ache@FreeBSD.org> 1) POSIX requires rand(3) return values to be in the [0, RAND_MAX] range,
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
/freebsd/include/
H A Dstdlib.hdiff 476d9314d6247b8386926960081689e8f395594c Wed Jul 03 23:21:54 CEST 2013 Andrey A. Chernov <ache@FreeBSD.org> 1) POSIX requires rand(3) return values to be in the [0, RAND_MAX] range,
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