Object.assign(Number.prototype, {
    halfUp: function (this: number, scale: number): number {
        return parseFloat(this.toFixed(scale));
    },
    toPercent: function (this: number, scale?: number): string {
        if (typeof scale === 'number') {
            return (this * 100).halfUp(scale) + '%';
        } else {
            return (this * 100) + '%';
        }
    }
});

export function randomInt(min: number, max: number): number {
    if (min > max) {
        let temp = min;
        min = max;
        max = temp;
    }
    let result = Math.ceil(min + (max - min) * Math.random());
    if (result >= max) {
        result = max;
    }
    return result;
}
