UNPKG

will-util

Version:
24 lines (23 loc) 836 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RandomUtility = void 0; class RandomUtility { static getRandomNum(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } static random(len = 6, alphabets = this.ALPHABETS) { let result = ""; let max = alphabets.length - 1; for (let i = 0; i < len; i++) { let idx = this.getRandomNum(1, max); result += alphabets[idx - 1]; } return result; } static randomNumber(len = 6, alphabets = this.NUMERICS) { return this.random(len, alphabets); } } exports.RandomUtility = RandomUtility; RandomUtility.ALPHABETS = Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); RandomUtility.NUMERICS = Array.from("0123456789");