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


C# Random.NextEnum方法代码示例

本文整理汇总了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));
            }
        }
开发者ID:tbashore,项目名称:TLib.NET,代码行数:11,代码来源:RandomTests.cs

示例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)];
        }
开发者ID:Iyemon-018,项目名称:Dev,代码行数:28,代码来源:MainViewModel.cs

示例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));
            }
        }
开发者ID:tbashore,项目名称:TLib.NET,代码行数:9,代码来源:RandomTests.cs

示例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);
 }
开发者ID:ExRam,项目名称:DotSpatial-PCL,代码行数:18,代码来源:PointSymbolizer.cs

示例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);
        }
开发者ID:DIVEROVIEDO,项目名称:DotSpatial,代码行数:12,代码来源:SimpleSymbol.cs

示例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);
        }
开发者ID:DIVEROVIEDO,项目名称:DotSpatial,代码行数:25,代码来源:SimpleStroke.cs

示例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);
 }
开发者ID:ExRam,项目名称:DotSpatial-PCL,代码行数:15,代码来源:CharacterSymbol.cs

示例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));
 }
开发者ID:yonghu86,项目名称:osharp,代码行数:6,代码来源:RandomExtensionsTest.cs

示例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);
     }
 }
开发者ID:joelmuzz,项目名称:DotSpatial,代码行数:24,代码来源:CartographicStroke.cs

示例10: NextEnumInRangeExceptFails

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

            r.NextEnum(SomeCode.Middle, SomeCode.Middle, SomeCode.Middle);
        }
开发者ID:tbashore,项目名称:TLib.NET,代码行数:6,代码来源:RandomTests.cs

示例11: NextEnumInRangeFails

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

            r.NextEnum(SomeCode.Last, SomeCode.First);
        }
开发者ID:tbashore,项目名称:TLib.NET,代码行数:6,代码来源:RandomTests.cs


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