For the simulation Make a large vector a multiple of 30 (why?). For the first set with probability of 50% make half the vector as 1 (boys) and other half 0 (girls). Shuffle this array. A good way to shuffle is a generate a random array of the same size as the large vector. Sort and keep track of the index. The index is the shuffled set. See help rand, sort for this. Reshape the vector to Nx5 array. Each row is a family. See help reshape. Use sum() to see how many boys in each family. Find rows (families) where boys are three. See help find. See what is the probability out of N. Run for multiple iteration. Enjoy Matlab.