public IHttpActionResult Post(OrderDTO orderDTO) { Order order = _mapper.Map <OrderDTO, Order>(orderDTO); order.Status = Status.Started; order.CreateDate = DateTime.Now; BetterRandom random = new BetterRandom(); var toppings = _distributedPizzaDbContext.Toppings.ToList(); var orderManager = new OrderManager(toppings, random); order.OrderReferenceId = GetNextSeqAPI(); //order.OrderReferenceId = Guid.NewGuid().ToString(); foreach (var pizza in order.Pizza) { int toppingsTogenerate = random.Next(1, 3); for (var x = 0; x < toppingsTogenerate; x++) { int index = random.Next(toppings.Count); var topping = toppings[index]; pizza.Toppings.Add(topping); } } _distributedPizzaDbContext.Orders.Add(order); _distributedPizzaDbContext.SaveChanges(); IStreamProcessingQueue queue; switch (order.QueueType) { case QueueType.Kafka: queue = new KafkaStreamProcessing(); break; case QueueType.AmazonSQS: queue = new AmazonSQSProcessingQueue(); break; default: queue = new KafkaStreamProcessing(); break; } queue.QueueOrder(order); return(Ok(new OrderResponseDTO { OrderReferenceId = order.OrderReferenceId })); }
public void GenerateRandomCustomer() { var random = new BetterRandom(); var customerManager = new CustomerManager(random); List <Customer> customers = new List <Customer>(); for (var x = 0; x < 9; x++) { var customer = customerManager.GetRandomCustomer(random.Next(0, 6)); customers.Add(customer); } var count = customers.Count; }
/// <summary> /// Randomizes the list, be arbitrarily reordering /// sublists of stride elements. As the stride approaches /// the size of the list, the options become very /// limited. /// </summary> /// <remarks> /// This could take a while for very large list /// sizes. /// </remarks> public LSL_List llListRandomize(LSL_List src, int stride) { LSL_List result; BetterRandom rand = new BetterRandom(); int chunkk; int[] chunks; m_host.AddScriptLPS(1); if (stride <= 0) { stride = 1; } // Stride MUST be a factor of the list length // If not, then return the src list. This also // traps those cases where stride > length. if (src.Length != stride && src.Length % stride == 0) { chunkk = src.Length/stride; chunks = new int[chunkk]; for (int i = 0; i < chunkk; i++) { chunks[i] = i; } // Knuth shuffle the chunkk index for (int i = chunkk - 1; i > 0; i--) { // Elect an unrandomized chunk to swap int index = rand.Next(i + 1); // and swap position with first unrandomized chunk int tmp = chunks[i]; chunks[i] = chunks[index]; chunks[index] = tmp; } // Construct the randomized list result = new LSL_List(); for (int i = 0; i < chunkk; i++) { for (int j = 0; j < stride; j++) { result.Add(src.Data[chunks[i] * stride + j]); } } } else { object[] array = new object[src.Length]; Array.Copy(src.Data, 0, array, 0, src.Length); result = new LSL_List(array); } return result; }