博客
关于我
模拟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/

你可能感兴趣的文章
php预定义常量&变量
查看>>
R 集成算法③ 随机森林
查看>>
php验证码背景色设置无效
查看>>
php验证邮箱是否有效
查看>>
PHP高性能分布式应用服务器框架-SwooleDistributed
查看>>
PHP高效、轻量级表格数据处理库 OpenSpout
查看>>
R 数据缺失的处理
查看>>
php:$_ENV 和 getenv区别
查看>>
pickle模块
查看>>
pid控制
查看>>
PID控制介绍-ChatGPT4o作答
查看>>
PID控制器数字化
查看>>
PIESDKDoNet二次开发配置注意事项
查看>>
PIL Image对图像进行点乘,加上常数(等像素操作)
查看>>
PIL.Image、cv2的img、bytes相互转换
查看>>
PIL.Image进行图像融合显示(Image.blend)
查看>>
Pillow lacks the JPEG 2000 plugin
查看>>
ping 命令的七种用法,看完瞬间成大神
查看>>
Pinia:$patch的使用场景
查看>>
Pinia:$subscribe()的使用场景
查看>>