import crypto from 'crypto'; export class Math { constructor() {} uuid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' .replace(/[xy]/g, (c) => { let r = global.Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }) .toUpperCase(); } checkUuid(uuid) { return uuid.search( /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i) !== -1 } random(min, max) { return global.Math.floor(min + (global.Math.random() * (max + 1 - min))); // return min + offset; } uniqueRandomArray(amount, from, to) { if (amount > to - from) { return []; } let found = []; while (found.length < amount) { let r = this.random(from, to); if (found.indexOf(r) === -1) { found.push(r); } } return found; } } exports.default = Math;