File tree Expand file tree Collapse file tree 5 files changed +5
-5
lines changed Expand file tree Collapse file tree 5 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -1066,7 +1066,7 @@ <h2 id="c_1">C++ 随机数的正确生成方式</h2>
1066
1066
</ ul >
1067
1067
< p > 类似的还有 < code > std::uniform_real_distribution</ code > 用于生成浮点数,< code > std::normal_distribution</ code > 用于生成正太分布的随机数,< code > std::poisson_distribution</ code > 用于生成泊松分布的随机数,等等。</ p >
1068
1068
< p > 如果喜欢老式的函数调用风格接口,可以封装一个新的 C++ 重置版安全 < code > rand</ code > :</ p >
1069
- < pre > < code class ="language-cpp "> thread_local std::mt19937 gen(std::random_device() ()); // 每线程一个,互不冲突
1069
+ < pre > < code class ="language-cpp "> thread_local std::mt19937 gen(std::random_device{} ()); // 每线程一个,互不冲突
1070
1070
1071
1071
int randint(int min, int max) {
1072
1072
return std::uniform_int_distribution<int>(min, max)(gen);
Original file line number Diff line number Diff line change @@ -292,7 +292,7 @@ <h2 id="_1">前言</h2>
292
292
< blockquote >
293
293
< p > < img src ="./img/bulb.png " height ="30px " width ="auto " style ="margin: 0; border: none "/> 本书还在持续更新中……要追番的话,可以在 < a href ="https://github.com/parallel101/cppguidebook "> GitHub</ a > 点一下右上角的 “Watch” 按钮,每当小彭老师提交新 commit,GitHub 会向你发送一封电子邮件,提醒你小彭老师更新了。</ p >
294
294
</ blockquote >
295
- < p > 更新时间:2024年09月20日 09:29:46 (UTC+08:00)</ p >
295
+ < p > 更新时间:2024年09月22日 21:08:12 (UTC+08:00)</ p >
296
296
< p > < a href ="https://parallel101.github.io/cppguidebook "> 在 GitHub Pages 浏览本书</ a > | < a href ="https://142857.red/book "> 在小彭老师自己维护的镜像上浏览本书</ a > </ p >
297
297
< h2 id ="_2 "> 格式约定</ h2 >
298
298
< blockquote >
Original file line number Diff line number Diff line change @@ -421,7 +421,7 @@ <h2 id="index-_1">前言</h2>
421
421
<blockquote>
422
422
<p><img src="../img/bulb.png" height="30px" width="auto" style="margin: 0; border: none"/> 本书还在持续更新中……要追番的话,可以在 <a href="https://github.com/parallel101/cppguidebook">GitHub</a> 点一下右上角的 “Watch” 按钮,每当小彭老师提交新 commit,GitHub 会向你发送一封电子邮件,提醒你小彭老师更新了。</p>
423
423
</blockquote>
424
- <p>更新时间:2024年09月20日 09:29:46 (UTC+08:00)</p>
424
+ <p>更新时间:2024年09月22日 21:08:12 (UTC+08:00)</p>
425
425
<p><a href="https://parallel101.github.io/cppguidebook">在 GitHub Pages 浏览本书</a> | <a href="https://142857.red/book">在小彭老师自己维护的镜像上浏览本书</a></p>
426
426
<h2 id="index-_2">格式约定</h2>
427
427
<blockquote>
@@ -1664,7 +1664,7 @@ <h2 id="cpp_tricks-c_1">C++ 随机数的正确生成方式</h2>
1664
1664
</ul>
1665
1665
<p>类似的还有 <code>std::uniform_real_distribution</code> 用于生成浮点数,<code>std::normal_distribution</code> 用于生成正太分布的随机数,<code>std::poisson_distribution</code> 用于生成泊松分布的随机数,等等。</p>
1666
1666
<p>如果喜欢老式的函数调用风格接口,可以封装一个新的 C++ 重置版安全 <code>rand</code>:</p>
1667
- <pre><code class="language-cpp">thread_local std::mt19937 gen(std::random_device() ()); // 每线程一个,互不冲突
1667
+ <pre><code class="language-cpp">thread_local std::mt19937 gen(std::random_device{} ()); // 每线程一个,互不冲突
1668
1668
1669
1669
int randint(int min, int max) {
1670
1670
return std::uniform_int_distribution<int>(min, max)(gen);
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments