Пример #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Online = TestarConexao();

            if (Online)
            {
                SorteioNegocio neg = new SorteioNegocio();

                if (neg.ModoOffline())
                {
                    Online = false;

                    if (!Aleatorio.TodosArquivosExiste())
                    {
                        Aleatorio.Serial();
                    }
                }
                else if (neg.Active())
                {
                    bancoSortearToolStripMenuItem.Visible = true;
                }
            }

            if (!Online)
            {
                sorteioToolStripMenuItem.Enabled = false;
                Aleatorio.desSerial();
                FormMessage.ShowMessegeWarning("O sistema funcionará no MODO OFFLINE!");
            }
        }
Пример #2
0
        /// <summary>
        /// genera un valor aleatorio aplicando la distribucion Poisson
        /// </summary>
        /// <param name="lambda"></param>
        /// <param name="tamanioMuestra"></param>
        /// <returns></returns>
        public static double[] generarPoisson(double lambda, int tamanioMuestra)
        {
            double[] v;
            v = new double[tamanioMuestra];

            double p = 1;
            double x = -1;
            double u = 0;

            double a = Math.Exp(-lambda);

            for (int j = 0; j < v.Length; j++)
            {
                p = 1;
                x = 0;
                do
                {
                    u = Aleatorio.getInstancia().NextDouble();
                    p = p * u;

                    x++;
                } while (p >= a);

                v[j] = x;
            }
            return(v);
        }
Пример #3
0
        //PATRON COMMAND
        public bool hayAlgoFueraDeLoNormal()
        {
            double probabilidad = 0.40;
            double numero       = Aleatorio.generadorNum();

            return(numero < probabilidad);
        }
Пример #4
0
        public static ISector CrearDecorador(int caudalLluvia, int temperatura, int velocidadViento)
        {
            int     caudal = Aleatorio.Next(100);
            ISector sector = new Sector(caudal);

            return(decorarSector(sector, caudalLluvia, temperatura, velocidadViento));
        }
Пример #5
0
        private TimeSpan generarTiempoEntreLlegada()
        {
            double lambda = pedidosPorHora / 60d;

            double tiempoEntreLlegada = (-1 / lambda) * Math.Log(1 - Aleatorio.getInstancia().NextDouble());

            return(TimeSpan.FromMinutes(tiempoEntreLlegada));
        }
Пример #6
0
        //METODO PARA STATE
        public void conducir()
        {
            Console.WriteLine("conduciendo ambulancia");

            int cont = 0;
            int random;

            while (cont != 6)
            {
                if (this.estado is Apagado)
                {
                    this.estado.encender();
                }

                if (this.estado is Roto)
                {
                    this.estado.arreglar();
                }

                random = Aleatorio.Next(0, 4);


                //CAMBIA DE ESTADOS ALEATORIAMENTE
                switch (random)
                {
                case 0:
                    if (!(this.estado is Apagado) && !(this.estado is Roto))
                    {
                        this.estado.apagar();
                    }
                    break;

                case 1:
                    if (!(this.estado is Apagado) && !(this.estado is Roto))
                    {
                        this.estado.acelerar();
                    }
                    break;

                case 2:
                    if (!(this.estado is PuntoMuerto) && !(this.estado is Apagado) && !(this.estado is Roto))
                    {
                        this.estado.desacelerar();
                    }
                    break;

                case 3:
                    if (!(this.estado is Roto) && !(this.estado is Apagado) && !(this.estado is PuntoMuerto))
                    {
                        this.estado.frenar();
                    }

                    break;
                }

                cont++;
            }
        }
Пример #7
0
        private void buttonSelecionar_Click(object sender, EventArgs e)
        {
            if (numericUpDown1.Value == 0)
            {
                return;
            }

            //lista de bilhetes livres para seleção
            List <UserControlBilhete> numBilhetes = new List <UserControlBilhete>();

            //preencher a lista de bilhestes livres
            foreach (Control item in flowLayoutPanel1.Controls)
            {
                UserControlBilhete b = (UserControlBilhete)item;
                if (b.Botao.Enabled && b.Botao.BackColor != Color.GreenYellow)
                {
                    numBilhetes.Add(b);
                }
            }

            if (numBilhetes.Count < (int)numericUpDown1.Value)
            {
                if (numBilhetes.Count == 0)
                {
                    FormMessage.ShowMessegeWarning("Todos os bilhetes já foram vendidos!");
                }
                else
                {
                    if (FormMessage.ShowMessegeQuestion("Há somente " + numBilhetes.Count + " bilhetes para serem vendidos, deseja selecionar todos?") == DialogResult.Yes)
                    {
                        foreach (var item in numBilhetes)
                        {
                            Button b = item.Botao;
                            BotaoSelcionado(b);
                        }
                    }
                }

                return;
            }

            //lista dos numeros aleatórios
            List <int> numA = Aleatorio.Gerar(numBilhetes.Count, (int)numericUpDown1.Value);

            //seleciona da lista com bilhetes sorteado
            foreach (var item in numA)
            {
                Button b = numBilhetes[item].Botao;
                BotaoSelcionado(b);
            }
            numericUpDown1.Value = 0;


            ContarVerde();
        }
Пример #8
0
        private void bancoSortearToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (FormMessage.ShowMessegeQuestion("Deseja embaralhar os bilhetes?") == DialogResult.Yes)
            {
                Aleatorio.BilheteAleatorio();
                Aleatorio.Serial();
            }

            Aleatorio.ListaVendedor(1);
            Aleatorio.ListaTxt();
        }
Пример #9
0
        public void chispa()
        {
            double probabilidad = 0.7;
            double incendio     = Aleatorio.generadorNum();

            if (incendio < probabilidad)
            {
                Console.WriteLine("Haciendo sonar la alarma de incendio de " + this.ToString());
                notificar();
            }
        }
Пример #10
0
        private ISector decorador()
        {
            ISector sector = null;
            int     lluvia = Aleatorio.Next(0, 501);

            sector = FabricaDeSectores.crearSector("sectorBase", sector, 0);
            sector = FabricaDeSectores.crearSector("diaLluvioso", sector, lluvia);



            return(sector);
        }
Пример #11
0
        /// <summary>
        /// genera un valor aleatorio aplicando la distribucion exponencial
        /// </summary>
        /// <param name="lambda"></param>
        /// <param name="tamanioMuestra"></param>
        /// <returns></returns>
        public static double[] generarExponencial(double lambda, int tamanioMuestra)
        {
            double[] v;
            v = new double[tamanioMuestra];

            double media = 1 / lambda;

            for (int i = 0; i < v.Length; i++)
            {
                v[i] = Math.Round(-media * Math.Log(1 - Aleatorio.getInstancia().NextDouble()), 4);
            }

            return(v);
        }
Пример #12
0
        public override ISector[][] construirSectores()
        {
            double caudaLluvia = Aleatorio.Next(1, 501);

            for (int i = 0; i < matriz.Length; i++)
            {
                for (int j = 0; j < matriz.Length; j++)
                {
                    matriz[i][j] = decorador();
                }
            }

            return(matriz);
        }
Пример #13
0
 private void Limpar()
 {
     maskedTextBoxCpf.Text = string.Empty;
     textBoxNome.Clear();
     textBoxEmail.Text     = "*****@*****.**";
     maskedTextBoxTel.Text = string.Empty;
     textBoxVendCod.Clear();
     textBoxVendNome.Clear();
     textBoxDescricaoSort.Clear();
     textBoxIdSort.Clear();
     flowLayoutPanel1.Controls.Clear();
     numericUpDown1.Value = 1;
     maskedTextBoxCpf.Select();
     controlBilhete = Aleatorio.NumSorteio();
 }
Пример #14
0
        public override ISector[][] construirSectores()
        {
            int temp   = Aleatorio.Next(30, 46);
            int viento = Aleatorio.Next(80, 251);
            int lluvia = Aleatorio.Next(0, 501);

            for (int i = 0; i < matriz.Length; i++)
            {
                for (int j = 0; j < matriz.Length; j++)
                {
                    matriz[i][j] = DecoradorSectores.CrearDecorador(lluvia, temp, viento);
                }
            }

            return(matriz);
        }
Пример #15
0
        public static Manzana generarManzana()
        {
            Esquina e1;
            Calle   calle;
            Manzana manzana = new Manzana();

            for (int i = 0; i < 4; i++)
            {
                e1    = new Esquina(Aleatorio.Next(2, 3));
                calle = new Calle(Aleatorio.Next(80, 101), Aleatorio.Next(2, 5), Aleatorio.Next(65, 100));
                manzana.agregar(e1);
                manzana.agregar(calle);
            }

            return(manzana);
        }
        public override ISector[][] construirSectores()
        {
            double temperatura = Aleatorio.Next(0, 45);
            double viento      = Aleatorio.Next(1, 251);
            double lluvia      = Aleatorio.Next(1, 501);


            for (int i = 0; i < matriz.Length; i++)
            {
                for (int j = 0; j < matriz.Length; j++)
                {
                    matriz[i][j] = decorador();
                }
            }

            return(matriz);
        }
        public void Aleatorio_Test()
        {
            int        max = 10, num;
            List <int> aceptados = new List <int>();
            Aleatorio  aleatorio = new Aleatorio(max);

            for (int i = 0; i < max; i++)
            {
                num = aleatorio.Next();
                aleatorio.aceptado(num);
                if (aceptados.Contains(num))
                {
                    Assert.Fail();
                }
                aceptados.Add(num);
            }
        }
        private ISector decorador()
        {
            ISector sector = null;

            int temp   = Aleatorio.Next(30, 46);
            int viento = Aleatorio.Next(80, 251);

            sector = FabricaDeSectores.crearSector("sectorBase", sector, 0);
            sector = FabricaDeSectores.crearSector("arbolesGrandes", sector, 0);
            sector = FabricaDeSectores.crearSector("genteAsustada", sector, 0);
            sector = FabricaDeSectores.crearSector("pastoSeco", sector, 0);
            sector = FabricaDeSectores.crearSector("muchoCalor", sector, temp);
            sector = FabricaDeSectores.crearSector("muchoViento", sector, viento);



            return(sector);
        }
Пример #19
0
        public override void mojar(double agua)
        {
            //genera randoms para la cantidad de personas asustadas
            int cantidadGente = Aleatorio.Next(1, 6);

            cantidadGente = 1;
            int    cont      = 0;
            double resultado = agua;

            while (cont < cantidadGente)
            {
                resultado = resultado * 0.25;
                cont++;
            }


            base.mojar(resultado);
        }
Пример #20
0
        public static Manzana generarManzanaConPlaza()
        {
            Esquina e1;
            Calle   calle;
            Manzana manzana = new Manzana();
            Plaza   plaza   = new Plaza("", Aleatorio.Next(40, 60), Aleatorio.Next(5, 25), Aleatorio.Next(10, 20));

            for (int i = 0; i < 4; i++)
            {
                e1    = new Esquina(Aleatorio.Next(2, 3));
                calle = new Calle(Aleatorio.Next(80, 101), Aleatorio.Next(2, 5), Aleatorio.Next(65, 100));
                manzana.agregar(e1);
                manzana.agregar(calle);
            }
            manzana.agregar(plaza);

            return(manzana);
        }
Пример #21
0
        public async Task <bool> EnviarAsync([FromBody] Aleatorio aleatorio)
        {
            string connectionStringImpar = "Endpoint=sb://serviceparcial.servicebus.windows.net/;SharedAccessKeyName=enviar;SharedAccessKey=uTr8jT99xnTdzaCOWQGyIUrxJgZgnWtGUrfdHTry/M4=;EntityPath=qimpar";
            string queueNameImpar        = "qimpar";
            string connectionStringPar   = "Endpoint=sb://serviceparcial.servicebus.windows.net/;SharedAccessKeyName=enviar;SharedAccessKey=pOIXetI2MmqLgsi9jxvH5f/evOy2HWXMljqB7jipUoE=;EntityPath=qpar";
            string queueNamePar          = "qpar";
            string mensaje = JsonConvert.SerializeObject(aleatorio);

            Console.WriteLine(mensaje);
            if (parImpar(aleatorio.ValorRandom))
            {
                // create a Service Bus client
                await using (ServiceBusClient client = new ServiceBusClient(connectionStringPar))
                {
                    // create a sender for the queue
                    ServiceBusSender sender = client.CreateSender(queueNamePar);

                    // create a message that we can send
                    ServiceBusMessage message = new ServiceBusMessage(mensaje);

                    // send the message
                    await sender.SendMessageAsync(message);

                    Console.WriteLine($"Sent a single message to the queue: {queueNamePar}");
                }
            }//Par
            else
            {
                await using (ServiceBusClient client = new ServiceBusClient(connectionStringImpar))
                {
                    // create a sender for the queue
                    ServiceBusSender sender = client.CreateSender(queueNameImpar);

                    // create a message that we can send
                    ServiceBusMessage message = new ServiceBusMessage(mensaje);

                    // send the message
                    await sender.SendMessageAsync(message);

                    Console.WriteLine($"Sent a single message to the queue: {queueNameImpar}");
                }
            } //Impar
            return(true);
        }
Пример #22
0
        private void buttonSortear_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            flowLayoutPanelBilhete.Controls.Clear();
            NumSorteio(infoSort.sorteiobilhetequant, true);

            //gera uma lista de numeros sorteados baseado na quantidade de prêmios
            List <int> num = Aleatorio.Gerar(colBilhete.Count + 1, colItens.Sum(i => i.Quant));

            //gera uma lista de número não repetido baseado na quantidade produto
            List <int>         num2  = Aleatorio.Gerar(colItens.Sum(i => i.Quant) + 1, colItens.Sum(i => i.Quant));
            List <ProdutoInfo> lProd = new List <ProdutoInfo>();

            //adiciona os prêmios retidas vezes baseado na quantidade do mesmo
            foreach (var item in colItens)
            {
                for (int i = 0; i < item.Quant; i++)
                {
                    lProd.Add(item.Prod);
                }
            }

            int cont = 0;

            colSorteado = new SorteadoColecao();
            for (int i = 0; i < num.Count; i++)
            {
                UserControlBilhete b = (UserControlBilhete)flowLayoutPanelBilhete.Controls[num[i] - 1];

                SorteadoInfo s = new SorteadoInfo
                {
                    Prod    = lProd[num2[cont++] - 1], //seleciona o prêmio de forma aleatória e vincula a um sorteado
                    Bilhete = colBilhete.Where(w => w.bilhetenum == colBilhete[num[i] - 1].bilhetenum).FirstOrDefault(),
                };

                colSorteado.Add(s);
                b.Sorteado(s);
                b.Botao.BackColor = Color.Blue;
                b.Botao.ForeColor = Color.Blue;
            }

            SalvarTxt();
            this.Cursor = Cursors.Default;
        }
Пример #23
0
        private static ISector decorarSector(ISector sector, int caudalLluvia, int temperatura, int velocidadViento)
        {
            double probabilidad = 0.2;

            if (Aleatorio.generadorNum() < probabilidad)
            {
                sector = FabricaDeSectores.crearSector("pastoSeco", sector, 0);
            }

            if (Aleatorio.generadorNum() < probabilidad)
            {
                sector = FabricaDeSectores.crearSector("arbolesGrandes", sector, 0);
            }

            if (Aleatorio.generadorNum() < probabilidad)
            {
                sector = FabricaDeSectores.crearSector("genteAsustada", sector, 0);
            }

            if (temperatura > 30)
            {
                sector = FabricaDeSectores.crearSector("muchoCalor", sector, temperatura);
            }

            if (velocidadViento > 80)
            {
                sector = FabricaDeSectores.crearSector("muchoViento", sector, velocidadViento);
            }
            //Probabilidad de dia lluvioso
            bool   lluvia  = false;
            double pLluvia = 0.2;

            if (Aleatorio.generadorNum() < pLluvia)
            {
                lluvia = true;
            }

            if (caudalLluvia > 0 && lluvia)
            {
                sector = FabricaDeSectores.crearSector("diaLluvioso", sector, caudalLluvia);
            }

            return(sector);
        }
Пример #24
0
        /// <summary>
        /// genera dos valores aleatorios aplicando la distribucion normal
        /// </summary>
        /// <param name="n"></param>
        /// <param name="media"></param>
        /// <param name="desviacion"></param>
        /// <returns></returns>
        public static double[] generarNormal(int n, double media, double desviacion)
        {
            pi = Math.PI;


            double[] v;
            v = new double[n];

            int i = 0;

            while (i < v.Length)
            {
                double aux1 = Aleatorio.getInstancia().NextDouble() * 1;
                double aux2 = Aleatorio.getInstancia().NextDouble() * 1;

                double z1 = Math.Sqrt(-2 * Math.Log(aux1)) * (Math.Sin(2 * pi * aux2));
                double z2 = Math.Sqrt(-2 * Math.Log(aux1)) * (Math.Cos(2 * pi * aux2));

                double variable1 = media + desviacion * (z1);
                double variable2 = media + desviacion * (z2);

                v[i]     = Math.Round(variable1, 4);
                v[i + 1] = Math.Round(variable2, 4);

                i = i + 2;
            }
            //for (int i = 0; i < v.Length; i + 2)
            //{
            //    double aux1 = r1.NextDouble() * 1;
            //    double aux2 = r2.NextDouble() * 1;

            //    double z1 = Math.Sqrt(-2 * Math.Log(aux1)) * (Math.Sin(2 * pi * aux2));
            //    double z2 = Math.Sqrt(-2 * Math.Log(aux1)) * (Math.Cos(2 * pi * aux2));

            //    double variable1 = media + desviacion * (z1);
            //    double variable2 = media + desviacion * (z2);

            //    v[i] = Math.Round(variable1, 4);
            //    v[i + 1] = Math.Round(variable2, 4);

            //}

            return(v);
        }
Пример #25
0
        public static int generarRandomPoisson(double lambda, int valorInicialX)
        {
            double p = 1;
            int    x = valorInicialX;
            double u = 0;

            double a = Math.Exp(-lambda);

            p = 1;
            x = 0;
            do
            {
                u = Aleatorio.getInstancia().NextDouble();
                p = p * u;

                x++;
            } while (p >= a);

            return(x);
        }
Пример #26
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (FormVendedor formVendedor = new FormVendedor(false))
            {
                if (formVendedor.ShowDialog(this) == DialogResult.Yes)
                {
                    infoConc = formVendedor.infoConc;
                    maskedTextBoxCpf.Text = infoConc.concorrentecpf;
                    textBoxNome.Text      = infoConc.concorrentenome;
                    textBoxEmail.Text     = infoConc.concorrenteemail;
                    maskedTextBoxTel.Text = infoConc.concorrentetelefone;
                    buttonSort.Enabled    = true;

                    if (!string.IsNullOrEmpty(textBoxIdSort.Text))
                    {
                        controlBilhete = Aleatorio.NumSorteio();
                        ListaBilhete();
                    }
                }
            }
        }
Пример #27
0
        static void Main(string[] args)
        {
            Aleatorio alea = delegate(int max)
            {
                int    promedio = 0;
                int[]  array    = new int[5];
                Random random   = new Random();
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = random.Next(0, max);
                }

                for (int i = 0; i < array.Length; i++)
                {
                    promedio = promedio + array[i];
                }
                promedio = promedio * array.Length;
                return(promedio);
            };


            Console.WriteLine("El promedio es:" + alea(6));
        }
Пример #28
0
 public override ISector crearSector(ISector sector)
 {
     return(new Sector(Aleatorio.Next(101)));
 }
Пример #29
0
 //CONSTRUCTOR
 public Policia(Manejador sucesor) : base(sucesor)
 {
     lugares     = new List <ILugar>();
     ordenes     = generarOrdenes();
     numeroOrden = Aleatorio.Next(0, 2);
 }
Пример #30
0
 /// <summary>
 /// genera un valor aleatorio aplicando la distribucion uniforme
 /// </summary>
 /// <param name="min"></param>
 /// <param name="max"></param>
 /// <returns></returns>
 public static double generarUniforme(double min, double max)
 {
     return(Math.Round(Aleatorio.getInstancia().NextDouble() * (max - min) + min, 4));
 }