本文整理汇总了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));
}
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}