2
$\begingroup$

I am trying to make a function which gives us a 1/7 chance of doubling up, or a 6/7 chance of losing $20. Each time the function runs should be an independent event. I have modeled it as follows:

f:= RandomChoice[{1/7, 6/7} -> {Function[b, 2b], Function[b, b -20]}](* 1/7 chance of doubling up; 6/7 of losing $20 *)
trialRun1 = NestList[f, 200,5]
trialRun2 = NestList[f, 200,5]
trialRun3 = NestList[f, 200,5]
trialRun4 = NestList[f, 200,5]
trialRun5 = NestList[f, 200,5]

which yields

Out[231]= {200,400,800,1600,3200,6400}

Out[232]= {200,400,800,1600,3200,6400}

Out[233]= {200,180,160,140,120,100}

Out[234]= {200,180,160,140,120,100}

Out[235]= {200,180,160,140,120,100}

As you can see, this is incorrect. f has a 1/7 chance of being the doubling funciton, and a 6/7 chance of being the "lose $20 function". The events are dependent. How to fix?

$\endgroup$
4
$\begingroup$
f := RandomChoice[{1/7, 6/7} -> {2 #, # - 20}] &

trialRun1 = NestList[f, 200, 5]
trialRun2 = NestList[f, 200, 5]
trialRun3 = NestList[f, 200, 5]
trialRun4 = NestList[f, 200, 5]
trialRun5 = NestList[f, 200, 5]

(* {200, 400, 380, 360, 340, 320}

{200, 180, 160, 140, 120, 100}

{200, 180, 160, 320, 640, 1280}

{200, 180, 160, 320, 300, 280}

{200, 180, 360, 340, 320, 300} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.