这两个月工作巨多,直到今天才有时间写点骚东西。

可是要写点什么比较好呢?这时候看到了隔壁桌面上放着一张福彩,我脑子里有画面了。(所以这位赌狗不是我,我不买彩票)

为了方便以后支持更多的彩票,直接搞个类

class Gamble {
    static dualColor(red: number = 6, blue: number = 1) {
        const reds: [number, number] = [1, 33];
        const blues: [number, number] = [1, 16];

        return [this.randomVal(reds, red), this.randomVal(blues, blue)];
    }

    private static randomVal(
        fromto: number[],
        total: number,
        temp: number[] = [],
    ): number[] {
        const [head, ...body] = (!temp.length
            ? [...Array(fromto[1]).keys()]
                  .map(item => item + 1)
                  .splice(fromto[0] - 1)
            : fromto
        ).sort(() => Math.random() - 0.5);
        return !total
            ? temp
            : this.randomVal(body, total - 1, temp.concat(head));
    }
}