public string ServeCustomer(StockController controller) { Thread.Sleep(Rnd.NextInt(5)); TShirt shirt = TShirtProvider.SelectRandomShirt(); string code = shirt.Code; //assuming customer will always buy/sell a shirt bool custSells = Rnd.TrueWithProb(1.0 / 6.0); //customer want to sell a shirt 1/6th of the time if (custSells) { int quantity = Rnd.NextInt(9) + 1; controller.BuyShirts(code, quantity); return($"Bought {quantity} of {shirt}"); } else { bool success = controller.TrySellShirt(code); if (success) { return($"Sold {shirt}"); } else { return($"Couldn't sell {shirt}: Out of stock"); } } }
public static TShirt SelectRandomShirt() { int selectedIndex = Rnd.NextInt(AllShirts.Length); return(AllShirts[selectedIndex]); }