mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 09:33:49 +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 {
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user