# R Difference between rbinom and sample

I'm trying to model a Roulette game where if you bet on red (out of red(18/37), black(18/37), green(1/37)) and if you the ball lands on red you win 1 dollar and if it doesn't you lose $1. So in this case, is it a binomial distribution? Since there are only 2 outcomes from the gamblers perspective, red or not red. If thats the case are these 2 R functions the same? set.seed(3) sample(c(0,1),100,replace=T,prob=c(19/37,18/37)) rbinom(n = 100, size = 1, prob = 18/37)  ## 2 Answers Yes they are. sample draws random samples from categorical distribution, while rbinom from binomial distribution. Categorical distribution with two classes is a generalization of Bernoulli distribution. Binomial distribution is a distribution of$n\$ Bernoulli trials. If you had multiple trials and multiple categories, you'd use multinomial distribution.

• Just to expand on the question, if instead of betting on colour I was betting on number, could it still be a binomial distribution? Since again from the point of view of the gambler, the ball either lands on the number or does not. Would this result be the same as uniform distribution? Commented Apr 9, 2018 at 13:20
• @jmich738 it would be ok for any binary bet, so for example, you could bet for x > 34.67 etc
– Tim
Commented Apr 9, 2018 at 13:53

Yes, these functions appear to generate the same output. To more clearly see this, try the following code

n <- 100
seed.val <- 3
set.seed(seed.val)
x <- sample(c(0,1),n,replace=T,prob=c(19/37,18/37))
set.seed(seed.val)
y <- rbinom(n = n, size = 1, prob = 18/37)
cbind(x,y)


You will obtain the same output.

• This wouldn't need to prove anything: they could use different implementations, so the results wouldn't be identical, yet would be valid.
– Tim
Commented Apr 9, 2018 at 13:04
• The results do seem to be identical. I actually tried doing this before but got different results. Didn't know that you need to set.seed each time you run a function. I thought I just need to set it once. Commented Apr 9, 2018 at 13:18
• The code was not meant to prove that they were the same, but to demonstrate that they are generating the same sequences. Will revise answer to reflect this. Commented Apr 9, 2018 at 13:43