mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-26 11:10:58 +02:00
[refactor] Moved getRandombyte to its own TS file
Also made use of `getRandomInt`
This commit is contained in:
+6
-8
@@ -1,13 +1,15 @@
|
||||
import {AllServers} from "../src/Server";
|
||||
import {getRandomByte} from "./helpers/getRandomByte";
|
||||
|
||||
/* Functions to deal with manipulating IP addresses*/
|
||||
|
||||
//Generate a random IP address
|
||||
//Will not return an IP address that already exists in the AllServers array
|
||||
function createRandomIp() {
|
||||
var ip = createRandomByte(99) +'.' +
|
||||
createRandomByte(9) +'.' +
|
||||
createRandomByte(9) +'.' +
|
||||
createRandomByte(9);
|
||||
var ip = getRandomByte(99) + '.' +
|
||||
getRandomByte(9) + '.' +
|
||||
getRandomByte(9) + '.' +
|
||||
getRandomByte(9);
|
||||
|
||||
//If the Ip already exists, recurse to create a new one
|
||||
if (ipExists(ip)) {
|
||||
@@ -28,10 +30,6 @@ function ipExists(ip) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function createRandomByte(n=9) {
|
||||
return Math.round(Math.random()*n);
|
||||
}
|
||||
|
||||
function isValidIPAddress(ipaddress) {
|
||||
if (/^(25[0-6]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-6]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-6]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-6]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user