The Wayback Machine - https://web.archive.org/web/20180615235651/http://ja.cppreference.com:80/w/cpp/numeric/random/random_device
名前空間
変種
操作

std::random_device

提供: cppreference.com
< cpp‎ | numeric‎ | random
 
 
 
擬似乱数生成
エンジンとエンジンアダプタ
Original:
Engines and engine adaptors
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ジェネレータ
Original:
Generators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
random_device
(C++11)
ディストリビューション
Original:
Distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
一様分布
Original:
Uniform distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ベルヌーイ分布
Original:
Bernoulli distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ポアソン分布
Original:
Poisson distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
正規分布
Original:
Normal distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
サンプリング分布
Original:
Sampling distributions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シードシーケンス
Original:
Seed Sequences
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Cライブラリ
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
 
ヘッダ <random> で定義
class random_device;
(C++11およびそれ以降)

std::random_device は非決定的な乱数を生成する一様分布した整数の乱数ジェネレータです。

処理系が非決定的な生成源 (ハードウェアデバイスなど) を利用できない場合、 std::random_device は処理系定義の擬似乱数エンジンを用いて実装されることがあります。 この場合、各 std::random_device オブジェクトは同じ数値列を生成するかもしれません。

目次

[編集]メンバ型

メンバ型 定義
result_typeunsignedint

[編集]メンバ関数

構築
エンジンを構築します
(パブリックメンバ関数)[edit]
operator=
(deleted)
代入演算子は削除されています
(パブリックメンバ関数)
生成
エンジンの状態を進めて生成された値を返します
(パブリックメンバ関数)[edit]
特性
非決定的な乱数ジェネレータのエントロピーの見積りを取得します
(パブリックメンバ関数)[edit]
[static]
出力範囲の有り得る最小値を取得します
(パブリック静的メンバ関数)[edit]
[static]
出力範囲の有り得る最大値を取得します
(パブリック静的メンバ関数)[edit]

[編集]ノート

std::random_device が非決定的でない有名な例は MinGW です (bug 338)。 コミュニティによる MinGW 用の random_device サポートの実装があります (mingw-std-random_device)。

[編集]

#include <iostream>#include <string>#include <map>#include <random>   int main(){ std::random_device rd;std::map<int, int> hist;std::uniform_int_distribution<int> dist(0, 9);for(int n =0; n <20000;++n){++hist[dist(rd)];// note: demo only: the performance of many // implementations of random_device degrades sharply// once the entropy pool is exhausted. For practical use// random_device is generally only used to seed // a PRNG such as mt19937}for(auto p : hist){std::cout<< p.first<<" : "<<std::string(p.second/100, '*')<<'\n';}}

出力例:

0 : ******************** 1 : ******************* 2 : ******************** 3 : ******************** 4 : ******************** 5 : ******************* 6 : ******************** 7 : ******************** 8 : ******************* 9 : ********************
close