PerformRandomOperation(IDataInteraction dataProvider, IOutputProvider outputProvider, ILogger logger) { int sellerId; int buyerId; int shareId; decimal sharePrice; int purchaseQuantity; try { int numberOfTraders = dataProvider.GetNumberOfTraders(); if (numberOfTraders > 1) { List <int> availableSellers = dataProvider.GetAvailableSellers(); if (availableSellers.Count > 0) { sellerId = availableSellers[new Random().Next(0, availableSellers.Count)]; } else { throw new Exception("No traders with shares"); } buyerId = new Random().Next(1, numberOfTraders + 1); while (sellerId == buyerId) { buyerId = new Random().Next(1, numberOfTraders + 1); } if (buyerId == sellerId) { throw new Exception("buyerId == sellerId"); } } else { throw new Exception("Not enough traders for a transaction"); } List <int> availableShares = dataProvider.GetAvailableShares(sellerId); #if DEBUG outputProvider.WriteLine("Available shares types = " + availableShares.Count); #endif logger.Write("Available shares types = " + availableShares.Count); shareId = availableShares[new Random().Next(0, availableShares.Count)]; sharePrice = dataProvider.GetSharePrice(shareId); purchaseQuantity = new Random().Next(1, dataProvider.GetShareQuantityFromPortfoio(sellerId, shareId) + 1); return(sellerId, buyerId, shareId, sharePrice, purchaseQuantity); //UpdateDatabase(dataProvider, outputProvider, logger, sellerId, buyerId, shareId, sharePrice, purchaseQuantity); } catch (Exception e) { outputProvider.WriteLine(e.Message); logger.Write(e.Message); } return(0, 0, 0, 0M, 0); }