' podonne ' sbrforum ' 10-02-2011 Module BookLayoffSimulation Sub Main() Randomize(Timer) Dim never_layoff As Single = 0.0 For x = 0 To 100000 never_layoff += ResolveGame(1 + Rnd() * 100, 1 + Rnd() * 100, Single.MaxValue) Next Dim sometimes_layoff As Single = 0.0 For x = 0 To 100000 sometimes_layoff += ResolveGame(1 + Rnd() * 100, 1 + Rnd() * 100, 2.0) Next Dim always_layoff As Single = 0.0 For x = 0 To 100000 always_layoff += ResolveGame(1 + Rnd() * 100, 1 + Rnd() * 100, 1.0) Next Console.WriteLine("Book profit with no layoff: $" & never_layoff & ", $" & never_layoff / 100000 & "/game") Console.WriteLine("Book profit with layoff when larger is 2x smaller: $" & sometimes_layoff & ", $" & sometimes_layoff / 100000 & "/game") Console.WriteLine("Book profit with always layoff any imbalance: $" & always_layoff & ", $" & always_layoff / 100000 & "/game") Console.Read() End Sub Function ResolveGame(ByVal dollars_for As Integer, ByVal dollars_against As Integer, ByVal layoff_limit As Single) As Single Dim layoff_dollars = 0.0 'figureout the larger and smaller amounts, wehther they were for or against doesn't matter after this point Dim smaller = Math.Min(dollars_for, dollars_against) Dim larger = Math.Max(dollars_for, dollars_against) 'if the ratio of larger to smaller is greater than the layoff_limit, lay off some of the action 'layoff_dollars layed off on larger will cause each outcome to be exactly the same If larger / smaller > layoff_limit Then layoff_dollars = (layoff_limit - larger / smaller) * smaller 'calculate the payouts in either event (note that if layoff_dollars is 0.0 then it has no effect Dim smaller_payout = smaller + smaller * (10 / 11) + layoff_dollars Dim larger_payout = larger + larger * (10 / 11) - layoff_dollars * (10 / 11) 'resolve the event If Rnd() > 0.5 Then Return (larger + smaller) - smaller_payout Else Return (larger + smaller) - larger_payout End If End Function End Module