lets create 1000 random families with two children - boys or girls

families <- data.frame(child1=rbinom(1000, 1, 0.5), child2=rbinom(1000, 1, 0.5))

Select a random child form our families and ask if their sibling is of the same sex or not, do it 10000 times and collect the results:

[edit - I am an idiot - why the f did I resample from already randomly generated families - could have just generated a larger world and found an average, but leaving it as it was]

issame <- c()
for(i in 1:100000){
familynr <- sample(1:1000,1) #juhuslik perekond
childnr <- sample(1:2, 1) #juhuslik laps
issame[i] <-families[familynr, childnr]==families[familynr, as.integer(!(childnr-1))+1] #kontrollime, kas on sama, kui teine laps
}

library(ggplot2)
#paneme pildile
qplot(issame)