mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-30 03:23:48 +01:00
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:
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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user