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