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


C# Random.nextInt方法代码示例

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

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

示例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);
     }
 }
开发者ID:CurtHagenlocher,项目名称:OrcSharp,代码行数:14,代码来源:TestMurmur3.cs

示例4: randomDateStyle

 private static DateFormat randomDateStyle(Random random)
 {
     return DATE_STYLES[random.nextInt(DATE_STYLES.Length)];
 }
开发者ID:apache,项目名称:lucenenet,代码行数:4,代码来源:TestNumericQueryParser.cs

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


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