博客
关于我
模拟T次投掷骰子
阅读量:162 次
发布时间:2019-02-28

本文共 864 字,大约阅读时间需要 2 分钟。

模拟投掷骰子

代码

package Rolls;import Counter.Counter;import common.StdOut;import common.StdRandom;/** Copyright (C), 2020-2020, XXX有限公司 * FileName: Rolls * Author:   cakin * Date:     2020/1/11 * Description: 模拟投掷骰子 */public class Rolls {    public static void main(String[] args) {        int T = Integer.parseInt(args[0]);        int SIDES = 6;        Counter[] rolls = new Counter[SIDES + 1];        for (int i = 1; i <= SIDES; i++) {            rolls[i] = new Counter(i + "'s");        }        for (int t = 0; t < T; t++) {            int random = StdRandom.nextInt(SIDES) + 1;            rolls[random].incrementCount();        }        // 输出结果        for (int i = 1; i <= SIDES; i++) {            StdOut.println(i + "'s count: " + rolls[i].getCount());        }    }}

测试结果

当投掷1000000次的结果如下:

166995 1's166249 2's166429 3's167018 4's166639 5's166670 6's

代码参考

// 代码参考

转载地址:http://efqj.baihongyu.com/

你可能感兴趣的文章
numpy 用法
查看>>
Numpy 科学计算库详解
查看>>
Numpy.fft.fft和numpy.fft.fftfreq有什么不同
查看>>
Numpy.ndarray对象不可调用
查看>>
Numpy:按多个条件过滤行?
查看>>
Numpy:条件总和
查看>>
numpy、cv2等操作图片基本操作
查看>>
numpy判断对应位置是否相等,all、any的使用
查看>>
Numpy如何使用np.umprod重写range函数中i的python
查看>>
numpy数组替换其中的值(如1替换为255)
查看>>
numpy数组索引-ChatGPT4o作答
查看>>
NUMPY矢量化np.prod不能构造具有超过32个操作数的ufunc
查看>>
Numpy矩阵与通用函数
查看>>
numpy绘制热力图
查看>>
numpy转PIL 报错TypeError: Cannot handle this data type
查看>>
Nutch + solr 这个配合不错哦
查看>>
NutzCodeInsight 2.0.7 发布,为 nutz-sqltpl 提供友好的 ide 支持
查看>>
NutzWk 5.1.5 发布,Java 微服务分布式开发框架
查看>>
NUUO网络视频录像机 css_parser.php 任意文件读取漏洞复现
查看>>
NuxtJS 接口转发详解:Nitro 的用法与注意事项
查看>>