Created
April 7, 2016 05:19
-
-
Save takashi1975/5e68bf112bf9c7368b205e0ea5c2a3b6 to your computer and use it in GitHub Desktop.
C++11 ランダム 例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <random> | |
//処理例 | |
{ | |
//乱数の初期化 | |
std::mt19937 rng; | |
{ | |
// 非決定的な乱数生成器 | |
std::random_device rnd; | |
// シード指定 | |
rng.seed(rnd()); | |
} | |
// 抽選範囲(1〜10) | |
std::uniform_int_distribution<int> rand10(1, 10); | |
// ランダム抽選 | |
auto test = static_cast<int>(rand10(rng)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment