import { randomInt } from 'crypto';

const DEFAULT_ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';

export function generateCode(length = 10, alphabet = DEFAULT_ALPHABET) {
  let code = '';
  for (let index = 0; index < length; index += 1) {
    code += alphabet[randomInt(0, alphabet.length)];
  }
  return code;
}
