mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user