Skip to content

Instantly share code, notes, and snippets.

@wakuteka
Last active December 31, 2015 10:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wakuteka/7973660 to your computer and use it in GitHub Desktop.
> library(random)
# 関数が5つしかないシンプルなパッケージです。
> ls("package:random")
[1] "quotaCheck" "randomNumbers" "randomQuota"
[4] "randomSequence" "randomStrings"
# randomNumbers()は重複を許した乱数列を生成します。
# runif()とは違い、出力されるのは全てint型の整数です。
> randomNumbers(n=20,min=1,max=100,col=5,base=10,check=TRUE)
V1 V2 V3 V4 V5
[1,] 58 22 75 3 52
[2,] 93 16 91 69 22
[3,] 69 3 45 7 6
[4,] 72 71 53 35 46
# randomSequence()は重複を許さない乱数列を生成します。
# 数列をランダムに並べ替えているということもできます。
# sample()関数だとreplace=FALSEオプションに相当します。
> randomSequence(min=1,max=20,col=5)
V1 V2 V3 V4 V5
[1,] 11 1 5 9 20
[2,] 18 7 2 16 6
[3,] 4 10 15 13 8
[4,] 12 3 19 17 14
# ランダムな文字列を簡単に生成することもできます。
> randomStrings(n=10,len=5,digits=TRUE,upperalpha=TRUE,
+ loweralpha=TRUE,unique=TRUE,check=TRUE)
V1
[1,] "GRyft"
[2,] "aL38g"
[3,] "Q5YBi"
[4,] "p4tIi"
[5,] "sq72A"
[6,] "iri1D"
[7,] "AsOt9"
[8,] "F8Z8A"
[9,] "PZNkP"
[10,] "9bVxt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment