ClearAll[SleepingBeautyExperiment] SleepingBeautyExperiment[reps_Integer] := Module[{gotheadsonwaking, wakenings, coinresult}, gotheadsonwaking = 0; wakenings = 0; Do[ coinresult = RandomChoice[{"heads", "tails"}]; wakenings++; If[coinresult === "heads", gotheadsonwaking++; , wakenings++; ] , {reps} ]; Print["Wakenings over ", reps, " experiments: ", wakenings]; gotheadsonwaking/wakenings ] out = N@SleepingBeautyExperiment[10^6]; Print["Results of experiment: Sleeping Beauty should estimate a credence of: ", out]