當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。