// Port allocator that assigns random unique ports in a high range
// Uses range 40000-49999 to avoid conflicts with common applications
const PORT_RANGE_START = 40000;
const PORT_RANGE_END = 49999;
export class PortAllocator {
    usedPorts = new Set();
    allocate() {
        const rangeSize = PORT_RANGE_END - PORT_RANGE_START + 1;
        // Safety check to prevent infinite loop
        if (this.usedPorts.size >= rangeSize) {
            throw new Error("No available ports in range");
        }
        let port;
        do {
            port = PORT_RANGE_START + Math.floor(Math.random() * rangeSize);
        } while (this.usedPorts.has(port));
        this.usedPorts.add(port);
        return port;
    }
}
//# sourceMappingURL=port-allocator.js.map