Last active
May 13, 2021 15:56
-
-
Save tetlabo/2b3055152fdb4d99911f45b1492b9244 to your computer and use it in GitHub Desktop.
R 3.6以前と以後の乱数生成器の動作を比べてみる
This file contains hidden or 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
# 実行環境の確認 | |
R.version | |
# デフォルトの乱数生成器を確認 | |
RNGkind() | |
# 巨大な数を生成する | |
m <- (5/16)*2^32 | |
m | |
# デフォルトの乱数生成器を確認 | |
RNGkind(sample.kind = "Rejection") | |
# 1:m の、一様分布に従う乱数を生成し、3で割った余りを集計する | |
num <- table(sample(m, 1e6, replace = TRUE) %% 5) | |
num | |
# 分布をプロット | |
barplot(num, main = "R 3.6以降の乱数生成器の結果", family = "Japan1GothicBBB") | |
# R 3.6以前の乱数生成器を使用 | |
RNGkind(sample.kind = "Rounding") | |
# 1:m の、一様分布に従う乱数を生成し、3で割った余りを集計する | |
num2 <- table(sample(m, 1e6, replace = TRUE) %% 5) | |
num2 | |
# 分布をプロット | |
barplot(num2, main = "R 3.6以前の乱数生成器の結果", family = "Japan1GothicBBB") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment