mirror of
https://github.com/corda/corda.git
synced 2025-01-23 21:08:48 +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)
|
Java_java_lang_Math_natRandom(JNIEnv*, jclass)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
int r = rand();
|
double r = static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
|
||||||
if (r == RAND_MAX) {
|
if (r < 0 or r >= 1) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return static_cast<double>(r) / static_cast<double>(RAND_MAX);
|
return r;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return drand48();
|
return drand48();
|
||||||
|
Loading…
Reference in New Issue
Block a user