# 2006 年 7 月 31 日作成 # じゃんけんの Simulation # 実験回数 rep=1000 res=rep(0,rep) # 何回勝負か match=30 for (i in 1:rep){ co=1 win=0 lose=0 en=0 game=rep(0,2*match) while(en<=match){ a=sign(sin(pi*trunc(runif(1,0,1)*3)*(2/3)-pi*trunc(runif(1,0,1)*3)*(2/3))) if(abs(a)>0){game[co]=a;co=co+1} if(a>0){win=win+a} if(a<0){lose=lose+a} res[i]=sum(game) en=max(abs(win),abs(lose)) } } op<-par(mfrow=c(2,1)) hist(res) hist(res/rep)