simulating rolling two dice

后端 未结 3 1103
Happy的楠姐
Happy的楠姐 2021-01-05 00:52

I am trying to simulate rolling two dice. I used:

d2 <- sample(1:6, 10^6, replace = T) + sample(1:6, 10^6, replace = T)

and get the expe

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-05 01:40

    I agree with David that nothing seems particularly wrong with your first option. Another way to go might be this, if you're really just after the sum of the two dice:

    sample(2:12,size = 100,replace = TRUE, prob = table(outer(1:6,1:6,"+")) / 36)
    

提交回复
热议问题