Skip to content

Update cpp_tricks.md: gen(std::random_device()()); 会被当成函数,无法编译 #46

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/cpp_tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ int main() {
如果喜欢老式的函数调用风格接口,可以封装一个新的 C++ 重置版安全 `rand`:

```cpp
thread_local std::mt19937 gen(std::random_device()()); // 每线程一个,互不冲突
thread_local std::mt19937 gen(std::random_device{}()); // 每线程一个,互不冲突

int randint(int min, int max) {
return std::uniform_int_distribution<int>(min, max)(gen);
Expand Down