mirror of
https://github.com/corda/corda.git
synced 2025-01-07 13:38:47 +00:00
tweak Math.natRandom for Windows to guarantee we never return anything outside [0,1)
This commit is contained in:
parent
3c237547ee
commit
1bca2e9e5d
@ -533,11 +533,11 @@ extern "C" JNIEXPORT jdouble JNICALL
|
||||
Java_java_lang_Math_natRandom(JNIEnv*, jclass)
|
||||
{
|
||||
#ifdef WIN32
|
||||
int r = rand();
|
||||
if (r == RAND_MAX) {
|
||||
double r = static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
|
||||
if (r < 0 or r >= 1) {
|
||||
return 0;
|
||||
} else {
|
||||
return static_cast<double>(r) / static_cast<double>(RAND_MAX);
|
||||
return r;
|
||||
}
|
||||
#else
|
||||
return drand48();
|
||||
|
Loading…
Reference in New Issue
Block a user