import { randomBytes } from "crypto";

const RECEIPT_CHARS = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";

/** 16-character unambiguous receipt code for ballot confirmation. */
export function generateReceiptCode(length = 16): string {
  const bytes = randomBytes(length);
  let result = "";
  for (let i = 0; i < length; i++) {
    result += RECEIPT_CHARS[bytes[i] % RECEIPT_CHARS.length];
  }
  return result;
}
