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


C# Random.NextDateTime方法代码示例

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


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

示例1: NextDateTime

        public void NextDateTime()
        {
            var r = new Random();

            var today = DateTime.Today.Date;
            var tomorrow = today.AddDays(1);

            for (var i = 0; i < 100; i++)
            {
                Assert.That(r.NextDateTime(today, tomorrow), Is.InRange(today, tomorrow));
                Assert.That(r.NextDateTime(today, today), Is.EqualTo(today));
            }
        }
开发者ID:tbashore,项目名称:TLib.NET,代码行数:13,代码来源:RandomTests.cs

示例2: NextDateTimeTest

        public void NextDateTimeTest()
        {
            Random rnd = new Random();
            DateTime dt = rnd.NextDateTime();
            Assert.IsTrue(dt >= DateTime.MinValue);
            Assert.IsTrue(dt <= DateTime.MaxValue);

            DateTime dtNow = DateTime.Now;
            DateTime dtMin = dtNow.AddMinutes(-10);
            DateTime dtMax = dtNow.AddMinutes(10);
            dt = rnd.NextDateTime(dtMin, dtMax);
            Assert.IsTrue(dt >= dtMin);
            Assert.IsTrue(dt <= dtMax);
        }
开发者ID:yonghu86,项目名称:osharp,代码行数:14,代码来源:RandomExtensionsTest.cs

示例3: NextDateTimeFails

        public void NextDateTimeFails()
        {
            var r = new Random();

            var today = DateTime.Today.Date;
            var tomorrow = today.AddDays(1);

            Console.Out.WriteLine(r.NextDateTime(tomorrow, today));
        }
开发者ID:tbashore,项目名称:TLib.NET,代码行数:9,代码来源:RandomTests.cs

示例4: GenerateRandomTestEntities

 public static List<TestEntity> GenerateRandomTestEntities(int sampleSize)
 {
     Random random = new Random();
     List<TestEntity> testEntities = new List<TestEntity>();
     for (int i = 0; i < sampleSize; i++)
     {
         testEntities.Add(new TestEntity
         {
             TestDate = random.NextDateTime(new DateTime(2000, 1, 1), new DateTime(2012, 1, 1)),
             TestInt = random.Next(),
             TestString = random.NextString(1000)
         });
     }
     return testEntities;
 }
开发者ID:bingdianfeishui,项目名称:StaticVoid.OrmPerformance,代码行数:15,代码来源:TestEntityHelpers.cs

示例5: UnitTestBase

 protected UnitTestBase()
 {
     List<TestEntity> entities = new List<TestEntity>();
     DateTime dt = DateTime.Now;
     Random rnd = new Random();
     for (int i = 0; i < 1000; i++)
     {
         entities.Add(new TestEntity()
         {
             Id = i + 1,
             Name = "Name" + (i + 1),
             AddDate = rnd.NextDateTime(dt.AddDays(-7), dt.AddDays(7)),
             IsDeleted = rnd.NextBoolean()
         });
     }
     Entities = entities;
 }
开发者ID:Jesn,项目名称:osharp,代码行数:17,代码来源:UnitTestBase.cs

示例6: NextDateTimeTest

        public void NextDateTimeTest()
        {
            var rnd = new Random();
            var min = new DateTime(2009, 12, 30, 0, 0, 0);
            var max = new DateTime(2010, 1, 2, 0, 0, 0);

            double TRIALS = 100000;
            var dates = new List<DateTime>((int)TRIALS);
            for (int i = 0; i < TRIALS; ++i) {
                var dt = rnd.NextDateTime(min, max);
                dates.Add(dt);
            }

            //verify even distribution
            var avg = (max.Ticks + min.Ticks) / 2;
            var part = (max.Ticks - min.Ticks) / 4;

            var mid = avg; //					1/2
            var mid14 = avg - part; //			1/4
            var mid34 = avg + part;//			3/4

            double c1 = 0, c2 = 0, c3 = 0, c4 = 0;

            foreach (var dt in dates) {
                var t = dt.Ticks;
                if (t < mid14)
                    ++c1;
                else if (t >= mid14 && t < mid)
                    ++c2;
                else if (t >= mid && t < mid34)
                    ++c3;
                else if (t >= mid34)
                    ++c4;
            }

            double q1 = c1/TRIALS;
            double q2 = c2/TRIALS;
            double q3 = c3/TRIALS;
            double q4 = c4/TRIALS;

            Assert.AreEqual(0.25, q1, 0.01);
            Assert.AreEqual(0.25, q2, 0.01);
            Assert.AreEqual(0.25, q3, 0.01);
            Assert.AreEqual(0.25, q4, 0.01);
        }
开发者ID:jprichardson,项目名称:CommonLib,代码行数:45,代码来源:RandomExTest.cs

示例7: CreateRandomPacket

        private static Packet CreateRandomPacket(Random random)
        {
            Packet packet;
            do
            {
                DateTime packetTimestamp =
                    random.NextDateTime(PacketTimestamp.MinimumPacketTimestamp, PacketTimestamp.MaximumPacketTimestamp).ToUniversalTime().ToLocalTime();

                List<ILayer> layers = new List<ILayer>();
                EthernetLayer ethernetLayer = random.NextEthernetLayer();
                layers.Add(ethernetLayer);
                CreateRandomEthernetPayload(random, ethernetLayer, layers);
                packet = PacketBuilder.Build(packetTimestamp, layers);
            } while (packet.Length > 65536);
            return packet;
        }
开发者ID:rokugasenpai,项目名称:Pcap.Net,代码行数:16,代码来源:WiresharkCompareTests.cs

示例8: CreateRandomPacket

        private static Packet CreateRandomPacket(Random random)
        {
            Packet packet;
            do
            {
                // TODO. BUG: Limited timestamp due to Windows bug: https://connect.microsoft.com/VisualStudio/feedback/details/559198/net-4-datetime-tolocaltime-is-sometimes-wrong
                DateTime packetTimestamp =
                    random.NextDateTime(new DateTime(2010, 1, 1), new DateTime(2010, 12, 31)).ToUniversalTime().ToLocalTime();
                //random.NextDateTime(PacketTimestamp.MinimumPacketTimestamp, PacketTimestamp.MaximumPacketTimestamp).ToUniversalTime().ToLocalTime();

                List<ILayer> layers = new List<ILayer>();
                EthernetLayer ethernetLayer = random.NextEthernetLayer();
                layers.Add(ethernetLayer);
                CreateRandomEthernetPayload(random, ethernetLayer, layers);
                packet = PacketBuilder.Build(packetTimestamp, layers);
            } while (packet.Length > 65536);
            return packet;
        }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:18,代码来源:WiresharkCompareTests.cs


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