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


C# Random.NextByte方法代码示例

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


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

示例1: yield

        //public async Task<string> yield()
        public async Task yield()
        {
            // where else have we done css remoting?

            var r = new Random();

            body.Attribute("style").Value = "background-color: " +
                "rgb(" +
                    r.NextByte() + "," +
                    r.NextByte() + "," +
                    r.NextByte() +
                ")";


            // server side delay. progressbar shows up?
            //await Task.Delay(2500);

            System.Threading.Thread.Sleep(500);

            //return "ok";
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:22,代码来源:ApplicationWebService.cs

示例2: DnsOptResourceRecordTest

        public void DnsOptResourceRecordTest()
        {
            Random random = new Random();
            for (int i = 0; i != 100; ++i)
            {
                DnsDomainName domainName = random.NextDnsDomainName();
                ushort sendersUdpPayloadSize = random.NextUShort();
                byte extendedRcode = random.NextByte();
                DnsOptVersion version = (DnsOptVersion)random.NextByte();
                DnsOptFlags flags = (DnsOptFlags)random.NextUShort();
                DnsResourceDataOptions data = (DnsResourceDataOptions)random.NextDnsResourceData(DnsType.Opt);

                DnsOptResourceRecord record = new DnsOptResourceRecord(domainName, sendersUdpPayloadSize, extendedRcode, version, flags, data);
                
                Assert.AreEqual(domainName, record.DomainName);
                Assert.AreEqual(sendersUdpPayloadSize, record.SendersUdpPayloadSize);
                Assert.AreEqual(extendedRcode, record.ExtendedReturnCode);
                Assert.AreEqual(version, record.Version);
                Assert.AreEqual(flags, record.Flags);
                Assert.AreEqual(data, record.Data);
            }
        }
开发者ID:preyea,项目名称:Pcap.Net,代码行数:22,代码来源:DnsTests.cs

示例3: IpV4OptionRoutePointedAddressIndexErrorTest

 public void IpV4OptionRoutePointedAddressIndexErrorTest()
 {
     Random random = new Random();
     IpV4Option option = new IpV4OptionRecordRoute(random.NextByte(IpV4OptionRoute.PointedAddressIndexMaxValue + 1, byte.MaxValue + 1));
     Assert.IsNotNull(option);
     Assert.Fail();
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:7,代码来源:IpV4Tests.cs

示例4: IpV4OptionTimestampPointedIndexErrorTest

 public void IpV4OptionTimestampPointedIndexErrorTest()
 {
     Random random = new Random();
     IpV4Option option = new IpV4OptionTimestampOnly(0, random.NextByte(IpV4OptionTimestamp.PointedIndexMaxValue + 1, byte.MaxValue + 1));
     Assert.IsNotNull(option);
     Assert.Fail();
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:7,代码来源:IpV4Tests.cs

示例5: IpV4OptionTimestampOverflowErrorTest

 public void IpV4OptionTimestampOverflowErrorTest()
 {
     Random random = new Random();
     IpV4Option option = new IpV4OptionTimestampOnly(random.NextByte(IpV4OptionTimestamp.OverflowMaxValue + 1, byte.MaxValue + 1), 0);
     Assert.IsNotNull(option);
     Assert.Fail();
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:7,代码来源:IpV4Tests.cs

示例6: Mutate

 public DNA Mutate( Random rand, DNA oldDNA, TaskState task )
 {
     int maxOverlap = task.ProjectOptions.MaxOverlap;
     DNA newDNA = new DNA( oldDNA );
     Shape shape = newDNA.Shapes[rand.Next( newDNA.Shapes.Length )];
     shape.PreviousState = shape.Clone() as Shape;
     shape.Color = Color.FromArgb( rand.Next( task.ProjectOptions.MinAlpha, 256 ), rand.NextByte(),
                                   rand.NextByte(), rand.NextByte() );
     double area, maxArea = MaxPolygonArea * task.ImageWidth * task.ImageHeight;
     do {
         for( int i = 0; i < shape.Points.Length; i++ ) {
             shape.Points[i] = new PointF( rand.NextFloat( -maxOverlap, task.ImageWidth + maxOverlap ),
                                           rand.NextFloat( -maxOverlap, task.ImageHeight + maxOverlap ) );
         }
         area = CalculateArea( shape.Points );
     } while( area > maxArea );
     newDNA.LastMutation = MutationType.ReplaceShape;
     return newDNA;
 }
开发者ID:fragmer,项目名称:SuperImageEvolver,代码行数:19,代码来源:HarderMutator.cs

示例7: MutateShape

        void MutateShape( Random rand, DNA dna, Shape shape, TaskState task )
        {
            shape.PreviousState = shape.Clone() as Shape;
            switch( rand.Next( 10 ) ) {
                case 0:
                    shape.Color = Color.FromArgb( (byte)rand.Next( task.ProjectOptions.MinAlpha, 256 ), shape.Color.R,
                                                  shape.Color.G, shape.Color.B );
                    dna.LastMutation = MutationType.ReplaceColor;
                    if( rand.Next( 10 ) == 0 ) {
                        MutateMultiplePoints( shape, rand, dna, task );
                        dna.LastMutation = MutationType.ReplaceShape;
                    }
                    break;

                case 1:
                    shape.Color = Color.FromArgb( shape.Color.A, rand.NextByte(), shape.Color.G, shape.Color.B );
                    dna.LastMutation = MutationType.ReplaceColor;
                    if( rand.Next( 10 ) == 0 ) {
                        MutateMultiplePoints( shape, rand, dna, task );
                        dna.LastMutation = MutationType.ReplaceShape;
                    }
                    break;

                case 2:
                    shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, rand.NextByte(), shape.Color.B );
                    dna.LastMutation = MutationType.ReplaceColor;
                    if( rand.Next( 10 ) == 0 ) {
                        MutateMultiplePoints( shape, rand, dna, task );
                        dna.LastMutation = MutationType.ReplaceShape;
                    }
                    break;

                case 3:
                    shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, shape.Color.G, rand.NextByte() );
                    dna.LastMutation = MutationType.ReplaceColor;
                    if( rand.Next( 10 ) == 0 ) {
                        MutateMultiplePoints( shape, rand, dna, task );
                        dna.LastMutation = MutationType.ReplaceShape;
                    }
                    break;

                default:
                    MutateMultiplePoints( shape, rand, dna, task );
                    break;
            }
        }
开发者ID:fragmer,项目名称:SuperImageEvolver,代码行数:46,代码来源:HardMutator.cs

示例8: GetGrainTexture

        public static Texture2D GetGrainTexture(IGraphicsService graphicsService, int size)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");
              if (size < 1)
            throw new ArgumentOutOfRangeException("size", "size must be greater than 0.");

              var textures = GetNoiseTextures(graphicsService);
              Texture2D grainTexture;
              if (!textures.GrainTextures.TryGetValue(size, out grainTexture) || grainTexture.IsDisposed)
              {
            grainTexture = new Texture2D(graphicsService.GraphicsDevice, size, size, false, SurfaceFormat.Color);
            Color[] data = new Color[size * size];
            var random = new Random(1234567);
            for (int i = 0; i < data.Length; i++)
              data[i] = new Color(random.NextByte(), random.NextByte(), random.NextByte(), random.NextByte());

            grainTexture.SetData(data);

            textures.GrainTextures[size] = grainTexture;
              }

              return grainTexture;
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:24,代码来源:NoiseHelper.cs

示例9: ChangeColor

 static void ChangeColor( Random rand, Shape shape, TaskState task )
 {
     shape.PreviousState = shape.Clone() as Shape;
     switch( rand.Next( 4 ) ) {
         case 0:
             shape.Color = Color.FromArgb( rand.NextByte( task.ProjectOptions.MinAlpha, 256 ), shape.Color.R,
                                           shape.Color.G, shape.Color.B );
             break;
         case 1:
             shape.Color = Color.FromArgb( shape.Color.A, rand.NextByte(), shape.Color.G, shape.Color.B );
             break;
         case 2:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, rand.NextByte(), shape.Color.B );
             break;
         case 3:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, shape.Color.G, rand.NextByte() );
             break;
     }
 }
开发者ID:fragmer,项目名称:SuperImageEvolver,代码行数:19,代码来源:TranslateMutator.cs

示例10: ChangeColor

 void ChangeColor( Random rand, Shape shape, TaskState task )
 {
     shape.PreviousState = shape.Clone() as Shape;
     int delta = rand.NextByte( 1, (int)( MaxColorDelta + 1 ) ) * ( rand.Next( 2 ) == 0 ? 1 : -1 );
     switch( rand.Next( 4 ) ) {
         case 0:
             shape.Color =
                 Color.FromArgb(
                     Math.Max( task.ProjectOptions.MinAlpha, Math.Min( 255, shape.Color.A + delta ) ),
                     shape.Color.R, shape.Color.G, shape.Color.B );
             break;
         case 1:
             shape.Color = Color.FromArgb( shape.Color.A, Math.Max( 0, Math.Min( 255, shape.Color.R + delta ) ),
                                           shape.Color.G, shape.Color.B );
             break;
         case 2:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R,
                                           Math.Max( 0, Math.Min( 255, shape.Color.G + delta ) ), shape.Color.B );
             break;
         case 3:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, shape.Color.G,
                                           Math.Max( 0, Math.Min( 255, shape.Color.B + delta ) ) );
             break;
     }
 }
开发者ID:fragmer,项目名称:SuperImageEvolver,代码行数:25,代码来源:SoftTranslateMutator.cs


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