import crypto from 'crypto';
/** math functions*/
export class Math {

  constructor() {}
  /** will generate uuid*/
  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();
  }
  /** will check a uuid - if uuid*/
  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
  }
  /** get random value between min(inclusive) & max(inclusive)*/
  random(min, max) {
    return global.Math.floor(min + (global.Math.random() * (max + 1 - min)));
    // return min + offset;
  }
  /** fill a array with random values unique to the array*/
  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;