We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug
piecewise_linear_distribution doesn't produce the correct random number distribution.
piecewise_linear_distribution
Command-line test case
G:\Temp>type devcom_421634.cpp #include <cstdio> #include <iterator> #include <random> using namespace std; int main() { constexpr double intervals[] = {0, 1, 5}; constexpr double weights[] = {0, 1, 0}; constexpr double x = 2; constexpr double probability = 0.55; constexpr int total = 1'000'000; piecewise_linear_distribution<> distribution(begin(intervals), end(intervals), begin(weights)); mt19937 generator; int count = 0; for (int i = 0; i < total; ++i) { if (distribution(generator) < x) { ++count; } } const double frequency = static_cast<double>(count) / total; printf("Expected probability = %f\n", probability); printf("Actual frequency = %f (%d / %d)\n", frequency, count, total); } G:\Temp>cl /EHsc /W4 /WX devcom_421634.cpp 用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.26.28806 版 版权所有(C) Microsoft Corporation。保留所有权利。 devcom_421634.cpp Microsoft (R) Incremental Linker Version 14.26.28806.0 Copyright (C) Microsoft Corporation. All rights reserved. /out:devcom_421634.exe devcom_421634.obj G:\Temp>.\devcom_421634.exe Expected probability = 0.550000 Actual frequency = 0.718845 (718845 / 1000000)
STL version
Microsoft Visual Studio Community 2019 版本 16.6.3
Additional context
Also tracked on Developer Community as DevCom-421634 and by Microsoft-internal VSO-115939 / AB#115939.
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Describe the bug
piecewise_linear_distributiondoesn't produce the correct random number distribution.Command-line test case
STL version
Additional context
Also tracked on Developer Community as DevCom-421634 and by Microsoft-internal VSO-115939 / AB#115939.
The text was updated successfully, but these errors were encountered: