摘要: 1、函数不等概率返回0和1 2、调用2次, 结果 00 11 01 10 3、01和10,只是调换了顺序,概率应该是一样的 4、所以除了01好10,其他情况重做 5、代码验证 原函数 public static int sourceFunc() { return Math.random() > 0. 阅读全文
posted @ 2022-02-28 11:29 gabin 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 1、1~5随机函数 public static int sourceFunc() { return (int) (Math.random() * 5) + 1; } 2、将原函数转化为[0,1]返回值的函数 public static int tmpFunc() { int i = sourceFu 阅读全文
posted @ 2022-02-28 09:59 gabin 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 1、先证明随机数出现0~X的概率是X public static void main(String[] args) { for (int i = 1; i < 10; i++) { test(i / 10d); } } public static void test(double x) { int 阅读全文
posted @ 2022-02-28 09:21 gabin 阅读(230) 评论(0) 推荐(0) 编辑