本文整理匯總了C#中System.Random.NextULong方法的典型用法代碼示例。如果您正苦於以下問題:C# Random.NextULong方法的具體用法?C# Random.NextULong怎麽用?C# Random.NextULong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Random
的用法示例。
在下文中一共展示了Random.NextULong方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CastToULongOverflow
public void CastToULongOverflow()
{
Random random = new Random();
UInt128 value;
ulong overflow = random.NextULong(ulong.MaxValue);
try
{
value = (UInt128)(((BigInteger)ulong.MaxValue) + overflow + 1);
}
catch (Exception)
{
Assert.Fail();
return;
}
Assert.AreEqual(overflow, (ulong)value);
}
示例2: UInt128Test
public void UInt128Test()
{
Random random = new Random();
for (int i = 0; i != 1000; ++i)
{
UInt128 value = random.NextUInt128();
// Test comparisons.
Assert.AreEqual(value, value);
Assert.AreNotEqual(value, string.Empty);
Assert.AreNotEqual(value, UInt128.MaxValue);
Assert.AreNotEqual(value, UInt128.Zero);
// ReSharper disable EqualExpressionComparison
Assert.IsTrue(value == value);
Assert.IsFalse(value != value);
Assert.IsTrue(value <= value);
Assert.IsTrue(value >= value);
// ReSharper restore EqualExpressionComparison
if (value != UInt128.MaxValue)
{
Assert.IsTrue(value < value + 1);
Assert.IsTrue(value <= value + 1);
Assert.IsTrue(value + 1 > value);
Assert.IsTrue(value + 1 >= value);
}
// Test GetHashCode
Assert.IsNotNull(value.GetHashCode());
// Test Parse()
Assert.AreEqual(value, UInt128.Parse(value.ToString()));
Assert.AreEqual(value, UInt128.Parse(value.ToString(), CultureInfo.InvariantCulture));
Assert.AreEqual(value, UInt128.Parse(value.ToString(), NumberStyles.Integer));
// Test TryParse()
UInt128 actualValue;
Assert.IsTrue(UInt128.TryParse(value.ToString(), out actualValue));
Assert.AreEqual(value, actualValue);
Assert.IsTrue(UInt128.TryParse(value.ToString(CultureInfo.InvariantCulture), out actualValue));
Assert.AreEqual(value, actualValue);
// Cast to UInt64
ulong smallValue = random.NextULong();
Assert.AreEqual(smallValue, (ulong)((UInt128)smallValue));
}
}