๐Ÿ‘”Random

JS โŸฉ value โŸฉ primitive โŸฉ number โŸฉ Random

๐Ÿ‘‰ custom

// 2023.03.01 - 10:11 (โ€ข) first draft
// -----------------------------------------------------------

const { random, floor } = Math;

// โญ Random
// -----------------------------------------------------------
// - Random.int()
// - Random.float()
class Random {

    // โญ๏ธ Random.int(min, max)
    //    [min, max], (included)
    static int(min, max) {
        return random() * (max - min + 1) + min | 0;
    }

    // โญ๏ธ Random.float(min, max)
    // [min, max) (exclusive)
    static float(min, max) {
        return random() * (max - min) + min;
    }
    
}

// export
module.exports = {
    Random,
}

Last updated