本文整理汇总了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";
}
示例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);
}
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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;
}
}