ENH: improve uniformity of Random::position<label>() (closes #865)

- start/end values were underrepresented due to rounding.
  Now extend the range to include -0.5 and +0.5 beyond the usual
  range to ensure the same number density.
This commit is contained in:
Mark Olesen
2018-06-12 08:16:06 +02:00
parent dc521b95df
commit 3bcbb1615b
2 changed files with 30 additions and 14 deletions

View File

@ -174,7 +174,21 @@ int main(int argc, char *argv[])
}
}
cout<< nl << "Done." << endl;
// Test uniformity of random
{
List<label> samples(20, Zero);
Random rnd(123456);
for (label i=0; i < 1000*samples.size(); ++i)
{
++samples[rnd.position<label>(0,19)];
}
Info<< nl << "uniform [0,20)" << nl << " "
<< flatOutput(samples) << nl;
}
Info<< nl << "Done." << endl;
return 0;
}