Merge pull request #2444 from xmcclure/randfixes
authormonojenkins <jo.shields+jenkins@xamarin.com>
Fri, 15 Jan 2016 18:20:15 +0000 (18:20 +0000)
committermonojenkins <jo.shields+jenkins@xamarin.com>
Fri, 15 Jan 2016 18:20:15 +0000 (18:20 +0000)
Bugfixes in mono-rand.c

2 commits:

* Make mono-rand consistent (fixes threadpool on some UNIX systems)

  mono-rand.c defines a function interface and provides three implementations (Windows, modern UNIX, base C standard). The clients of this file (RNGCryptoServiceProvider.cs, threadpool-ms-io.c) appear to be consistent in how they use this interface, but the interface is not documented, and the C-only implementation deviates from it (the return value of init is different). The result is that threadpool-ms-io fails an assert when run on a system using the C-only implementation. I documented the interface and fixed the C-only quirk.

* Fix nonuniform distribution of mono_rand_try_get_uint32

  mono_rand_try_get_uint32 returns a value in a range min..max inclusive. Due to a math error the ‘max’ value will be returned only one out of every 2^32-1 calls to the function. This is currently harmless because the only current callers of this function (in threadpool-ms-io) will run fine even if their max value is never returned, but it could become a problem later.


Trivial merge