Probability of shuffling array
public python v1 · immutablefrom random import shuffledef test(x,f,to_n=100000): suc = 0 for i in xrange(0,to_n): shuffle(x) if f(x): suc+=1 return float(suc)/float(to_n)def one_got_same_color(a): for i in range(0,len(a),2): if a[i]==a[i+1]: return True return False#The following will simulate what's the probability for the#first kid to recieve a red ball or a blue ball#print test([1,1,2,2,3,3,4,4],lambda x: x[0]==1 and x[1]==2)print test([1,1,2,2,3,3,4,4],one_got_same_color)