mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 06:48:42 +02: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:
@@ -78,12 +78,11 @@ export function ipExists(ip: string): boolean {
|
||||
}
|
||||
|
||||
export function createUniqueRandomIp(): string {
|
||||
const ip = createRandomIp();
|
||||
|
||||
// If the Ip already exists, recurse to create a new one
|
||||
if (ipExists(ip)) {
|
||||
return createRandomIp();
|
||||
}
|
||||
let ip: string;
|
||||
// Repeat generating ip, until unique one is found
|
||||
do {
|
||||
ip = createRandomIp();
|
||||
} while (ipExists(ip));
|
||||
|
||||
return ip;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user