当前位置: 首页>>代码示例>>C#>>正文


C# RandomGenerator.Next方法代码示例

本文整理汇总了C#中RandomGenerator.Next方法的典型用法代码示例。如果您正苦于以下问题:C# RandomGenerator.Next方法的具体用法?C# RandomGenerator.Next怎么用?C# RandomGenerator.Next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RandomGenerator的用法示例。


在下文中一共展示了RandomGenerator.Next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestCalculadora

        public void TestCalculadora()
        {
            RandomGenerator r = new RandomGenerator();
            var persons = Builder<Person>.CreateListOfSize(tests * tests).
                    All().With(x => x.Age = r.Next(0, 100))
                         .And(x => x.Height = r.Next(90, 180))
                         .And(x => x.Weight = r.Next(10, 90))
                         .And(x => x.IsMan = r.Next())
                         .And(x => x.BMR = r.Next(100, 2000))
                         .And(x => x.Hip = r.Next(20, 60))
                         .And(x => x.Waist = r.Next(20, 60))
                         .And(x => x.Neck = r.Next(10, 30))
                         .Random(15).With(x => x.BMR = 0.0f)
                   .Build();
            foreach (Person p in persons)
            {
                Calculadora c = new Calculadora(p);
                int value = r.Next(-5, 7);
                if (value < 1 || value > 5)
                {
                    Assert.IsFalse(c.seleccionarCalculadora(value.ToString()));
                }
                else
                {
                    Assert.IsTrue(c.seleccionarCalculadora(value.ToString()));
                    if (value == 5)
                        Assert.IsFalse(c.estaActiva);
                }

            }
        }
开发者ID:JuanCastillo,项目名称:Calculadoras,代码行数:31,代码来源:UnitTest1.cs

示例2: ImageUrls

        /// <summary>
        /// Images the urls.
        /// </summary>
        /// <param name="max">The max.</param>
        /// <returns>A List.</returns>
        private static List<string> ImageUrls(int max, RandomGenerator randomGenerator)
        {
            var width = randomGenerator.Next(200, 300);
            var height = randomGenerator.Next(200, 300);
            var list = new List<string>();
            for (var i = 0; i < max; i++)
            {
                list.Add(string.Format("http://lorempixel.com/{0}/{1}", width, height));
            }

            return list;
        }
开发者ID:benpowell,项目名称:RavenLocal,代码行数:17,代码来源:FakeThings.cs

示例3: Example_Of_Method_Chaining

        public void Example_Of_Method_Chaining()
        {
            var generator = new RandomGenerator();

            var invoices = Builder<Invoice>.CreateListOfSize(50)
                .All().With(x => x.AmountDue = generator.Next(0m, 1000m))
                .Random(20).With(x => x.AmountDue = generator.Next(500m, 1000m))
                .Build();

            Find.SetInvoices(invoices);

            var result = Find.Invoices.With(x => x.AmountDue > 500m).Execute();

            Assert.That(result.Count(), Is.GreaterThan(20));
        }
开发者ID:josephbulger,项目名称:Learning,代码行数:15,代码来源:Test.cs

示例4: SeedLocacao

            //public int[] CodFilme { get; set; }
            public IList<Locacao> SeedLocacao()
            {
                var dayRandom = new RandomGenerator();
                Random valorRandom = new Random();
                
                DateTime min = new DateTime(2015, 1, 1);
                DateTime max = new DateTime(2015, 1, 28);

                var locacoes = Builder<Locacao>.CreateListOfSize(Relacoes).All()
                    .With(l => l.DatInLocacao = dayRandom.Next(min, max).ToString("dd-MM-yyyy"))
                    .With(l => l.DatFimLocacao = dayRandom.Next(min, max).ToString("dd-MM-yyyy"))
                    .With(l => l.ValorMulta = valorRandom.Next(0, 28))
                    .With(l => l.CodCliente = valorRandom.Next(1,Tamanho))
                    .With(l => l.CodFilme = valorRandom.Next(1,Tamanho)).Build();
                return locacoes;
            }
开发者ID:rikes,项目名称:TesteRedis,代码行数:17,代码来源:Locadora.cs

示例5: TestCalorias

        public void TestCalorias()
        {
            RandomGenerator r = new RandomGenerator();
            Calorias c = new Calorias();
            var persons = Builder<Person>.CreateListOfSize(tests).
                    All().With(x => x.Age = r.Next(1, 110))
                         .And(x => x.Height = r.Next(tests, 260))
                         .And(x => x.Weight = r.Next(0, 999))
                         .And(x => x.IsMan = r.Next())
                   .Build();
            foreach (Person p in persons)
            {
                float BMR = (float)((10 * p.Weight) + ((6.25 * p.Height) - (5 * p.Age)));
                float expected = BMR;

                if (p.IsMan)
                {
                    BMR += 5;
                }
                else
                {
                    BMR -= 161;
                }
                switch (p.NivelActividad)
                {
                    case NivelActividad.nivelActividad.sedentario:
                        expected *= 1.2f;
                        break;
                    case NivelActividad.nivelActividad.ligeramenteActivo:
                        expected *= 1.375f;
                        break;
                    case NivelActividad.nivelActividad.moderadamenteActivo:
                        expected *= 1.55f;
                        break;
                    case NivelActividad.nivelActividad.muyActivo:
                        expected *= 1.725f;
                        break;
                    case NivelActividad.nivelActividad.extraActivo:
                        expected *= 1.9f;
                        break;
                }

                float value = c.doOperation(p);
                Assert.AreEqual(expected, value);
            }
        }
开发者ID:JuanCastillo,项目名称:Calculadoras,代码行数:46,代码来源:UnitTest1.cs

示例6: When

        public override void When()
        {
            var randomGenerator = new RandomGenerator();
            var userConfigurations = Builder<UserConfiguration>.CreateListOfSize(5)
                .All().With(x => x.RowKey = string.Format("{0}-{1}", CardRowTypes.CONFIGURATION, randomGenerator.Next()))
                .Random(1).With(x => x.RowKey = TestValues.CONFIGURATION_ROW_KEY)
                .Build();

            this.TableStorageContext.Setup(x => x.CreateQuery<UserConfiguration>()).Returns(userConfigurations.AsQueryable());
            this.UserConfigurationKeyGenerator.Setup(x => x.GetRowKey(TestValues.CONFIGURATION_ID)).Returns(TestValues.CONFIGURATION_ROW_KEY);
            this.userConfiguration = this.UserConfigurationRepository.GetByUserId(TestValues.CONFIGURATION_ID);
        }
开发者ID:aenmeyk,项目名称:BrainThud,代码行数:12,代码来源:When_GetByUserId_is_called.cs

示例7: SeedCliente

            public IList<Cliente> SeedCliente()
            {
                var dayRandom = new RandomGenerator();
                var sexoRandom = new Random();

                DateTime min = new DateTime(1940, 1, 1);
                DateTime max = new DateTime(2000, 12, 28);
                char[] sexo = { 'F', 'M' };

                var clientes = Builder<Cliente>.CreateListOfSize(Tamanho).All()
                            .With(c => c.DatNascimento = dayRandom.Next(min, max).ToString("dd-MM-yyyy"))
                            .With(c => c.NomeCliente = Faker.Name.FullName())
                            .With(c => c.Sexo = sexo[sexoRandom.Next(sexo.Length)]).Build();

                return clientes;
            }
开发者ID:rikes,项目名称:TesteRedis,代码行数:16,代码来源:Locadora.cs

示例8: Comments

        private static List<Comment> Comments(User user, string thingId, int max, RandomGenerator randomGenerator)
        {
            var list = new List<Comment>();
            for (var i = 0; i < max; i++)
            {
                list.Add(new Comment()
                    {
                        ThingId = thingId,
                        UserId = user.Id,
                        Username = user.Username,
                        Email = user.Email,
                        Description = randomGenerator.Phrase(200),
                        CreationDate = randomGenerator.Next(DateTime.UtcNow.AddDays(-30), DateTime.UtcNow)
                    });
            }

            return list;
        }
开发者ID:benpowell,项目名称:RavenLocal,代码行数:18,代码来源:FakeThings.cs

示例9: Using_random_dates

        public void Using_random_dates()
        {
            var generator = new RandomGenerator();
            
            var products = Builder<Product>
                            .CreateListOfSize(100)
                            .All()
                                .With(x => x.Created = generator.Next(July.The(1), November.The(10)))
                            .Build();

            var expectedStart = new DateTime(DateTime.Now.Year, 7, 1, 00, 00, 00);
            var expectedEnd = new DateTime(DateTime.Now.Year, 11, 10, 00, 00, 00);

            foreach (var product in products)
            {
                Assert.That(product.Created, Is.AtLeast(expectedStart));
                Assert.That(product.Created, Is.AtMost(expectedEnd));
            }
        }
开发者ID:asiftasleem,项目名称:nbuilder,代码行数:19,代码来源:UsingFluentDates.cs

示例10: Fake

        /// <summary>
        /// Fakes the specified number of items.
        /// </summary>
        /// <param name="users">The users.</param>
        /// <param name="numberOfItems">The number of items.</param>
        /// <returns>
        /// A list.
        /// </returns>
        public static IList<Thing> Fake(ICollection<User> users, int numberOfItems)
        {
            var randomGenerator = new RandomGenerator();
            var things = Builder<Thing>
                .CreateListOfSize(numberOfItems)
                .All()
                .With(x => x.Id = string.Format("Thing-{0}", x.Id))
                .With(x => x.UserId = Pick<User>.RandomItemFrom((IList<User>)users).Id)
                .With(x => x.Latitude = users.Where(u => u.Id == x.UserId).FirstOrDefault().Latitude)
                .With(x => x.Longitude = users.Where(u => u.Id == x.UserId).FirstOrDefault().Longitude)
                .With(x => x.Description = randomGenerator.Phrase(500))
                .With(x => x.ImageUrls = ImageUrls(randomGenerator.Next(1, 5), randomGenerator))
                .Build();

            foreach (var thing in things)
            {
                thing.Comments = Comments(Pick<User>.RandomItemFrom((IList<User>)users), thing.Id, 5, randomGenerator);
                thing.Offers = Offers(Pick<User>.RandomItemFrom((IList<User>)users), thing.Id, 5, randomGenerator);
            }

            return things;
        }
开发者ID:benpowell,项目名称:RavenLocal,代码行数:30,代码来源:FakeThings.cs

示例11: UsingAGenerator

        public void UsingAGenerator()
        {
            var generator = new RandomGenerator();

            var products = Builder<Product>
                .CreateListOfSize(10)
                .All()
                    .With(x => x.PriceBeforeTax = generator.Next(50, 1000))
                .Build();


            foreach (var product in products)
            {
                Assert.That(product.PriceBeforeTax, Is.AtLeast(50m));
                Assert.That(product.PriceBeforeTax, Is.AtMost(1000m));
            }
        }
开发者ID:asiftasleem,项目名称:nbuilder,代码行数:17,代码来源:ListBuilderTests.cs

示例12: SeedFilme

            public IList<Filme> SeedFilme()
            {
                var dayRandom = new RandomGenerator();
                Random valorRandom = new Random();
                DateTime min = new DateTime(1998, 1, 1);
                DateTime max = new DateTime(2015, 12, 28);

                var filmesList = Builder<Filme>.CreateListOfSize(Tamanho).All()
                          .With(f => f.NomeFilme = Faker.Lorem.Sentence())
                          .With(f => f.DataCompra = dayRandom.Next(min, max).ToString("dd-MM-yyyy"))
                          .With(f => f.ValorFilme = (valorRandom.Next(10,90)))
                          .With(f => f.IndPais = valorRandom.Next(1, 3))
                          .With(f => f.CodCategoria = dayRandom.Next(0,CodCategoriaStatico)).Build();
                return filmesList;

            }
开发者ID:rikes,项目名称:TesteRedis,代码行数:16,代码来源:Locadora.cs

示例13: TestRangeClass

        public void TestRangeClass()
        {
            Random random = new Random();
            RandomGenerator ran = new RandomGenerator(random);
            float minimum = ran.Next(0, 9);
            var ranges = Builder<Range<float>>.CreateListOfSize(tests).All()
                .WithConstructor(() => new Range<float>(minimum, ran.Next(minimum + 1, 9999999)))
                .Build();
            foreach (Range<float> r in ranges)
            {
                for (int i = 0; i < tests; i++)
                {
                    float number;
                    if (ran.Next())
                    {
                        number = ran.Next(r.Minimum, r.Maximum);
                    }
                    else
                    {
                        if (ran.Next())
                        {
                            number = ran.Next(float.MinValue, r.Minimum - 1);
                        }
                        else
                        {
                            number = ran.Next(r.Maximum + 1, 9999999);
                        }
                    }
                    if (number >= r.Minimum && number <= r.Maximum)
                    {
                        Assert.IsTrue(r.ContainsValue(number));
                    }
                    else
                    {
                        Assert.IsFalse(r.ContainsValue(number));
                    }
                }

            }
        }
开发者ID:JuanCastillo,项目名称:Calculadoras,代码行数:40,代码来源:UnitTest1.cs

示例14: TestPesoIdeal

        public void TestPesoIdeal()
        {
            RandomGenerator r = new RandomGenerator();
            PesoIdeal c = new PesoIdeal();
            var persons = Builder<Person>.CreateListOfSize(tests + tests).
                    All().With(x => x.Age = r.Next(0, 110))
                         .And(x => x.Height = r.Next(tests, 260))
                         .And(x => x.Weight = r.Next(0, 200))
                         .And(x => x.IsMan = r.Next())
                   .Build();
            foreach (Person p in persons)
            {
                float expected = 0.0f;

                if (p.Age >= 18)
                {
                    expected = (float)((p.Weight) / (Math.Pow(p.Height / 100, 2)));
                }
                else
                {
                    expected = (float)(((p.Weight) / (Math.Pow(p.Height, 2))) * 10000);
                }
                float value = c.doOperation(p);
                Assert.AreEqual(expected, value);
            }
        }
开发者ID:JuanCastillo,项目名称:Calculadoras,代码行数:26,代码来源:UnitTest1.cs

示例15: TestGrasaCorporal

 public void TestGrasaCorporal()
 {
     RandomGenerator r = new RandomGenerator();
     GrasaCorporal c = new GrasaCorporal();
     var persons = Builder<Person>.CreateListOfSize(tests).
             All().With(x => x.Age = r.Next(2, 110))
                  .And(x => x.Height = r.Next(tests, 260))
                  .And(x => x.Weight = r.Next(0, 999))
                  .And(x => x.IsMan = r.Next())
                  .And(x => x.Hip = r.Next(20, 60))
                  .And(x => x.Waist = r.Next(20, 60))
                  .And(x => x.Neck = r.Next(10, 30))
            .Build();
     foreach (Person p in persons)
     {
         if (p.Age >= 18)
         {
             float expected;
             if (p.IsMan)
             {
                 expected = 495 / (float)(1.0324 - 0.19077 * (Math.Log10(p.Waist - p.Neck)) + 0.15456 * (Math.Log10(p.Height))) - 450;
             }
             else
             {
                 expected = 495 / (float)(1.29579 - 0.35004 * (Math.Log10((p.Hip + p.Waist) - p.Neck)) + 0.22100 * (Math.Log10(p.Height))) - 450;
             }
             float value = c.doOperation(p);
             Assert.AreEqual(expected, value);
         }
         else
         {
             try
             {
                 c.doOperation(p);
                 Assert.Fail("Debio dar error");
             }
             catch (NotSupportedException)
             {
                 Assert.IsTrue(true);
             }
         }
     }
 }
开发者ID:JuanCastillo,项目名称:Calculadoras,代码行数:43,代码来源:UnitTest1.cs


注:本文中的RandomGenerator.Next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。