I have written a function
roulette[n_,b_]:= With[{money=100,bins=Range[38]},Table[If[b == RandomChoice[bins], money += 35, money -= 1], {n}]]
to simulate n games of American roulette with a bet on b. The functions SubtractFrom and AddTo are not working as intended.
roulette[100,5]
returns the result
SubtractFrom: 100
is not a variable with a value, so its value cannot be changed and similarly for AddTo. Is there a way to use += and -= within the function roulette?
Note: If I do not use the localized environment and define money = 100 external to the function roulette, it will run the simulation once, but this is problematic when I try to use roulette with starting money=100 in more complicated ways.
With
withModule
? $\endgroup$