Fix unique ip generation

The previous implementation had a bug in it, where the generated IP
wouldn't be unique, if the generated IP wouldn't be unique two times in
a row.
This commit is contained in:
InDieTasten 2022-03-12 18:29:01 +01:00
parent bb433d4629
commit 17cba1d853

@ -78,12 +78,11 @@ export function ipExists(ip: string): boolean {
} }
export function createUniqueRandomIp(): string { export function createUniqueRandomIp(): string {
const ip = createRandomIp(); let ip: string;
// Repeat generating ip, until unique one is found
// If the Ip already exists, recurse to create a new one do {
if (ipExists(ip)) { ip = createRandomIp();
return createRandomIp(); } while (ipExists(ip));
}
return ip; return ip;
} }