⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdice.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
字号:
package megamek.test;import megamek.common.Compute;public class TestDice {    public static void testDice() {        // test RNG        long rolls = 1000000;        long[] hits = new long[11];            System.out.println("testing dice, " + rolls + " rolls...");            long start = System.currentTimeMillis();        for (long i = 0; i < rolls; i++) {            hits[megamek.common.Compute.d6(2)-2]++;        }        long end = System.currentTimeMillis();            System.out.println("done testing dice in " + (end - start) + " ms.");        for (int i = 0; i < hits.length; i++) {            System.out.println(                "hits on " + (i+2) + " : " + hits[i] + "; probability = " + ((double) hits[i] / (double) rolls));        }            int[][] pairs = new int[6][6];        System.out.println("testing streaks, " + rolls + " rolls...");            int nLastLastRoll = 1;        for (long i = 0; i < rolls; i++) {            int nRoll = Compute.d6();            pairs[nLastLastRoll - 1][nRoll - 1]++;            nLastLastRoll = nRoll;        }        for (int x = 0; x < pairs.length; x++) {            for (int y = 0; y < pairs[x].length; y++) {                System.out.println((x+1) + "," + (y+1) + ": " + pairs[x][y]);            }        }        // odd, but necessary        System.out.flush();    }        public static void main(String[] args) {        testDice();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -