-
-
Save Alan-Liang/15cfd22a944ab2dc6419780da4491a9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
大于14比例 0.6744 | |
小于-19比例 1 | |
无穿越比例 0.0924 | |
平均最大 25139.9954 | |
平均最小 -20667.7789 | |
平均最大穿越 4983.632 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { randomBytes } = require('crypto') | |
const { writeFileSync } = require('fs') | |
let 样本量 = 1e4, 随机数个数 = 1e4, 样本 = [], 使用样本 = './样本.json' | |
if (!使用样本) for (let j of Array(样本量).keys()) { | |
let 最大 = 0, 最小 = 0, 和 = 0, 穿越 = [] | |
for(let i of Array(随机数个数).keys()) { | |
const 旧和 = 和 | |
和 += 500 - 随机数() | |
if (和 * 旧和 <= 0) 穿越.push(i) | |
if (和 > 最大) 最大 = 和 | |
if (和 < 最小) 最小 = 和 | |
} | |
样本.push({ 最大, 最小, 和, 穿越 }) | |
if (j === 100 || j % 1000 === 0) console.log(j) | |
} | |
else { | |
样本 = require(使用样本) | |
样本量 = 样本.length | |
} | |
writeFileSync('样本.json', JSON.stringify(样本)) | |
const 大于14 = 样本.filter(x => x.最大 > 14000).length / 样本量 | |
const 小于负19 = 样本.filter(x => x.最小 < 19000).length / 样本量 | |
const 无穿越 = 样本.filter(x => x.穿越.filter(i => i > 200).length === 0).length / 样本量 | |
const 平均最大 = 样本.reduce((a, b) => a + b.最大, 0) / 样本量 | |
const 平均最小 = 样本.reduce((a, b) => a + b.最小, 0) / 样本量 | |
const 平均最大穿越 = 样本.reduce((a, b) => a + b.穿越[b.穿越.length - 1], 0) / 样本量 | |
console.log(`大于14比例\t${大于14}\n小于-19比例\t${小于负19}\n无穿越比例\t${无穿越}\n平均最大\t${平均最大}\n平均最小\t${平均最小}\n平均最大穿越\t${平均最大穿越}`) | |
function 随机数 () { | |
const 数字 = Array.from(randomBytes(2)).reduce((a, b) => (a & parseInt('11', 2)) * 0xff + b, 0) | |
if (数字 >= 1000) return 随机数() | |
return 数字 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment