本文整理汇总了C#中System.Random.nextInt方法的典型用法代码示例。如果您正苦于以下问题:C# Random.nextInt方法的具体用法?C# Random.nextInt怎么用?C# Random.nextInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Random
的用法示例。
在下文中一共展示了Random.nextInt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VacuumEnvironment
public VacuumEnvironment()
{
Random r = new Random();
envState = new VacuumEnvironmentState(
0 == r.nextInt(2) ? LocationState.Clean : LocationState.Dirty,
0 == r.nextInt(2) ? LocationState.Clean : LocationState.Dirty);
}
示例2: render
public override void render(Screen screen, Level level, int x, int y)
{
wRandom = new Random((int)((tickCount + (x / 2 - y) * 4311) / 10 * 54687121L + x * 3271612L + y * 3412987161L));
//TODO: wRandom.setSeed((tickCount + (x / 2 - y) * 4311) / 10 * 54687121L + x * 3271612L + y * 3412987161L);
int col = ColorHelper.get(500, 500, 520, 550);
int transitionColor1 = ColorHelper.get(3, 500, level.dirtColor - 111, level.dirtColor);
int transitionColor2 = ColorHelper.get(3, 500, level.sandColor - 110, level.sandColor);
bool u = !level.getTile(x, y - 1).connectsToLava;
bool d = !level.getTile(x, y + 1).connectsToLava;
bool l = !level.getTile(x - 1, y).connectsToLava;
bool r = !level.getTile(x + 1, y).connectsToLava;
bool su = u && level.getTile(x, y - 1).connectsToSand;
bool sd = d && level.getTile(x, y + 1).connectsToSand;
bool sl = l && level.getTile(x - 1, y).connectsToSand;
bool sr = r && level.getTile(x + 1, y).connectsToSand;
if (!u && !l)
{
screen.render(x * 16 + 0, y * 16 + 0, wRandom.nextInt(4), col, wRandom.nextInt(4));
}
else
screen.render(x * 16 + 0, y * 16 + 0, (l ? 14 : 15) + (u ? 0 : 1) * 32, (su || sl) ? transitionColor2 : transitionColor1, 0);
if (!u && !r)
{
screen.render(x * 16 + 8, y * 16 + 0, wRandom.nextInt(4), col, wRandom.nextInt(4));
}
else
screen.render(x * 16 + 8, y * 16 + 0, (r ? 16 : 15) + (u ? 0 : 1) * 32, (su || sr) ? transitionColor2 : transitionColor1, 0);
if (!d && !l)
{
screen.render(x * 16 + 0, y * 16 + 8, wRandom.nextInt(4), col, wRandom.nextInt(4));
}
else
screen.render(x * 16 + 0, y * 16 + 8, (l ? 14 : 15) + (d ? 2 : 1) * 32, (sd || sl) ? transitionColor2 : transitionColor1, 0);
if (!d && !r)
{
screen.render(x * 16 + 8, y * 16 + 8, wRandom.nextInt(4), col, wRandom.nextInt(4));
}
else
screen.render(x * 16 + 8, y * 16 + 8, (r ? 16 : 15) + (d ? 2 : 1) * 32, (sd || sr) ? transitionColor2 : transitionColor1, 0);
}
示例3: testHashCodesM3_32_ints
public void testHashCodesM3_32_ints()
{
int seed = 123;
Random rand = new Random(seed);
HashFunction hf = Hashing.murmur3_32(seed);
for (int i = 0; i < 1000; i++)
{
int val = rand.nextInt();
byte[] data = ByteBuffer.allocate(4).putInt(val).array();
int hc1 = hf.hashBytes(data).asInt();
int hc2 = Murmur3.hash32(data, data.length, seed);
Assert.Equal(hc1, hc2);
}
}
示例4: randomDateStyle
private static DateFormat randomDateStyle(Random random)
{
return DATE_STYLES[random.nextInt(DATE_STYLES.Length)];
}
示例5: testHashCodesM3_128_ints
public void testHashCodesM3_128_ints()
{
int seed = 123;
Random rand = new Random(seed);
HashFunction hf = Hashing.murmur3_128(seed);
for (int i = 0; i < 1000; i++)
{
int val = rand.nextInt();
byte[] data = ByteBuffer.allocate(4).putInt(val).array();
// guava stores the hashcodes in little endian order
ByteBuffer buf = ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN);
buf.put(hf.hashBytes(data).asBytes());
buf.flip();
long gl1 = buf.getLong();
long gl2 = buf.getLong(8);
long[] hc = Murmur3.hash128(data, 0, data.length, seed);
long m1 = hc[0];
long m2 = hc[1];
Assert.Equal(gl1, m1);
Assert.Equal(gl2, m2);
byte[] offsetData = new byte[data.length + 50];
Array.Copy(data, 0, offsetData, 50, data.length);
hc = Murmur3.hash128(offsetData, 50, data.length, seed);
Assert.Equal(gl1, hc[0]);
Assert.Equal(gl2, hc[1]);
}
}