def successfulstarts(eventprobnumtrials)"""assumes eventprob is float representing probability of single attempt being successful numtrials positive int returns list of the number of attempts needed before success for each trial ""triesbeforesuccess [for in range(numtrials)consecfailures while random random(eventprobconsecfailures + triesbeforesuccess append(consecfailuresreturn triesbeforesuccess random seed( probofsuccess numtrials distribution successfulstarts(probofsuccessnumtrialspylab hist(distributionbins pylab xlabel('tries before success'pylab ylabel('number of occurrences out of str(numtrials)pylab title('probability of starting each try str(probofsuccess)figure geometric distribution benford' distribution benford' law defines really strange distribution let be large set of decimal integers how frequently would you expect each digit to appear as the first digitmost of us would probably guess one ninth of the time and when people are making up sets of numbers ( faking experimental data or perpetrating financial fraudthis is typically true it is nothowevertypically true of many naturally occurring data sets insteadthey follow distribution predicted by benford' law set of decimal numbers is said to satisfy benford' law if the probability of the first digit being is consistent with (dlog ( /dfor examplethis law predicts that the probability of the first digit being is about %shockinglymany actual data sets seem to observe this law it is possible to show that the fibonacci sequencefor examplesatisfies it perfectly that' kind of plausiblesince the sequence is generated by formula it' less easy to understand why such diverse data sets as iphone pass codesthe number of twitter followers per userthe population of countriesor the distance of stars from the earth closely approximate benford' law the law is named after the physicist frank benfordwho published paper in showing that the law held on over , observations drawn from twenty different domains howeverit was first postulated in by the astronomer simon newcomb