本文整理汇总了C#中System.Random.NextEnum方法的典型用法代码示例。如果您正苦于以下问题:C# Random.NextEnum方法的具体用法?C# Random.NextEnum怎么用?C# Random.NextEnum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Random
的用法示例。
在下文中一共展示了Random.NextEnum方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NextEnumInRange
public void NextEnumInRange()
{
var r = new Random();
for (var i = 0; i < Enum.GetValues(typeof(SomeCode)).Length * 100; i++)
{
Assert.That(r.NextEnum(SomeCode.Undefined, SomeCode.Last), Is.InRange(SomeCode.Undefined, SomeCode.Last));
Assert.That(r.NextEnum(SomeCode.First, SomeCode.Last), Is.InRange(SomeCode.First, SomeCode.Last));
Assert.That(r.NextEnum(SomeCode.Middle, SomeCode.Middle), Is.EqualTo(SomeCode.Middle));
}
}
示例2: MainViewModel
/// <summary>
/// コンストラクタ
/// </summary>
public MainViewModel()
: base()
{
// データを作成する。
var r = new Random();
StaffList = new ObservableCollection<Staff>();
for (int i = 0; i < MaxStaffCount; i++)
{
// ランダムな値をそれぞれ設定する。
var staff = new Staff()
{
Id = i,
Age = r.Next(20, 50),
Name = NameList[i],
Role = r.NextEnum<Role>(Role.All),
};
StaffList.Add(staff);
}
// 初期値は適当に選択する。
SelectedStaff = StaffList[r.Next(0, StaffList.Count)];
}
示例3: NextEnum
public void NextEnum()
{
var r = new Random();
for (var i = 0; i < Enum.GetValues(typeof(SomeCode)).Length * 100; i++)
{
Assert.That(r.NextEnum<SomeCode>(), Is.InRange(SomeCode.Undefined, SomeCode.Last));
}
}
示例4: OnRandomize
/// <summary>
/// This controls randomly creating a single random symbol from the symbol types, and randomizing it.
/// </summary>
/// <param name="generator"></param>
protected override void OnRandomize(Random generator)
{
SymbolType type = generator.NextEnum<SymbolType>();
_symbols.Clear();
switch (type)
{
case SymbolType.Custom: _symbols.Add(new SimpleSymbol()); break;
case SymbolType.Character: _symbols.Add(new CharacterSymbol()); break;
case SymbolType.Picture: _symbols.Add(new CharacterSymbol()); break;
case SymbolType.Simple: _symbols.Add(new SimpleSymbol()); break;
}
// This part will actually randomize the sub-member
base.OnRandomize(generator);
}
示例5: OnRandomize
/// <summary>
/// Occurs during the randomizing process
/// </summary>
/// <param name="generator"></param>
protected override void OnRandomize(Random generator)
{
_color = generator.NextColor();
Opacity = generator.NextFloat();
_pointShape = generator.NextEnum<PointShape>();
base.OnRandomize(generator);
}
示例6: OnRandomize
///// <summary>
///// Adds SimpleStroke copy content
///// </summary>
///// <param name="copy"></param>
//protected override void OnCopy(Descriptor copy)
//{
// base.OnCopy(copy);
// ISimpleStroke ss = copy as ISimpleStroke;
// ss.Color = Color;
// ss.Width = Width;
// ss.DashStyle = this.DashStyle;
//}
/// <summary>
/// Handles randomization of simple stroke content
/// </summary>
/// <param name="generator">The random generator to use for randomizing characteristics.</param>
protected override void OnRandomize(Random generator)
{
_color = generator.NextColor();
Opacity = generator.NextFloat();
_width = generator.NextFloat(10);
_dashStyle = generator.NextEnum<DashStyle>();
base.OnRandomize(generator);
}
示例7: OnRandomize
/// <summary>
/// Extends the randomize code to include the character aspects, creating a random character.
/// However, since most fonts don't support full unicode values, a character from 0 to 255 is
/// chosen.
/// </summary>
/// <param name="generator">The random class generator</param>
protected override void OnRandomize(Random generator)
{
_color = generator.NextColor();
Opacity = generator.NextFloat();
_character = (char)generator.Next(0, 255);
_fontFamilyName = FontFamily.Families[generator.Next(0, FontFamily.Families.Length - 1)].Name;
_style = generator.NextEnum<FontStyle>();
base.OnRandomize(generator);
}
示例8: NextEnumTest
public void NextEnumTest()
{
Random rnd = new Random();
UriKind kind = rnd.NextEnum<UriKind>();
Assert.IsTrue(new[] { UriKind.Absolute, UriKind.Relative, UriKind.RelativeOrAbsolute }.Contains(kind));
}
示例9: OnRandomize
/// <summary>
/// Handles the randomization of the cartographic properties of this stroke.
/// </summary>
/// <param name="generator">The random class that generates the random numbers</param>
protected override void OnRandomize(Random generator)
{
base.OnRandomize(generator);
DashStyle = DashStyle.Custom;
_dashCap = generator.NextEnum<DashCap>();
_startCap = generator.NextEnum<LineCap>();
_endCap = generator.NextEnum<LineCap>();
_dashButtons = generator.NextBoolArray(1, 20);
_compoundButtons = generator.NextBoolArray(1, 5);
_offset = generator.NextFloat(10);
_joinType = generator.NextEnum<LineJoinType>();
int len = generator.Next(0, 1);
if (len > 0)
{
_decorations.Clear();
LineDecoration ld = new LineDecoration();
ld.Randomize(generator);
_decorations.Add(ld);
}
}
示例10: NextEnumInRangeExceptFails
public void NextEnumInRangeExceptFails()
{
var r = new Random();
r.NextEnum(SomeCode.Middle, SomeCode.Middle, SomeCode.Middle);
}
示例11: NextEnumInRangeFails
public void NextEnumInRangeFails()
{
var r = new Random();
r.NextEnum(SomeCode.Last, SomeCode.First);
}