export function generateHostName(components: number, origin?: string): string { let firsts = [ "absent", "angry", "clean", "crazy", "cool", "cold", "criminal", "dehydrated", "drunk", "dirty", "frisky", "flirty", "free", "freaky", "groggy", "happy", "horny", "hot", "icy", "illegal", "intense", "intoxicated", "moody", "mad", "mean", "nude", "lazy", "relaxed", "rude", "sad", "sleepy", "sneaky", "sweaty", "tipsy", "tired", "undressed", "unhappy", "uncanny", "unreal", "wet", ]; let seconds = [ "beautiful", "big", "bulky", "brainy", "blue", "cute", "dead", "fat", "feminine", "fit", "gorgeous", "green", "gross", "greasy", "glowing", "hard", "huge", "large", "lean", "masculine", "masked", "miniscule", "muscular", "moist", "muddy", "orange", "one-legged", "one-eyed", "red", "sassy", "sexy", "small", "smart", "skinny", "shreded", "soft", "strong", "tall", "trained", "tiny", "unfit", "ugly", "worn", ]; let thirds = [ "actor", "adulterer", "alien", "amputee", "amish", "alligator", "antilope", "athlete", "astronaut", "bird", "barista", "bodybuilder", "boxer", "cat", "chef", "camper", "communist", "cowboy", "cyclist", "dancer", "democrat", "dog", "drummer", "drunkard", "driver", "drawf", "dragqueen", "doctor", "dude", "farmer", "fighter", "fireman", "fluffer", "freak", "gardener", "gangster", "guard", "hippie", "hunter", "hobbit", "homeopat", "iceman", "idiot", "indian", "imp", "jackass", "jock", "junkie", "killer", "lawyer", "librarian", "lifter", "looser", "lumberjack", "martian", "mouse", "midget", "minion", "miner", "mormon", "narsisist", "nudist", "nurse", "officer", "parrot", "pianist", "pig", "police", "pornstar", "queen", "republican", "rockstar", "sexworker", "singer", "skibum", "stripper", "spaceman", "solicitor", "thug", "tourist", "undertaker", "warrior", "winner", "wizard", "zebra", "zombie" ]; // firsts = ["firsts1","firsts2"] // seconds = ["seconds1","seconds2"] // thirds = ["thirds1","thirds2"] let last = thirds[getRandomInt(3, thirds.length, origin)]; switch (components) { case 1: return `${last}` break; case 2: // If there are many temporary hosts, use two components instead of one to generate name let fr = getRandomInt(1, firsts.length + seconds.length, origin); let first = (fr >= firsts.length) ? seconds[fr - firsts.length] : firsts[fr]; return `${first}-${last}` case 3: // If there are many temporary hosts, use three components instead of two to generate name return `${firsts[getRandomInt(1, firsts.length, origin)]}-${seconds[getRandomInt(2, seconds.length, origin)]}-${last}` case 4: // If there are many temporary hosts, use four components instead of three to generate name return `${firsts[getRandomInt(1, firsts.length, origin)]}-${seconds[getRandomInt(2, seconds.length, origin)]}-${last}${getRandomInt(4, 99, origin) + 1}` case 5: // If there are many temporary hosts, use five components instead of four to generate name return `${firsts[getRandomInt(1, firsts.length, origin)]}-${seconds[getRandomInt(2, seconds.length, origin)]}-${last}${getRandomInt(4, 9999, origin) + 1}` default: throw "1 to 5 components only" } } export function calculateHash(str: string, lessThan: number) { var hash = 0, i, chr; if (str.length === 0) return hash; for (i = 0; i < str.length; i++) { chr = str.charCodeAt(i); hash = ((hash << 5) - hash) + chr; hash |= 0; // Convert to 32bit integer } return Math.abs(hash % lessThan); }; export function RandomString() { return `${Math.floor(Math.random() * 1000)}` //return `${Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)}` } export function getRandomInt(seed: number, max: number, origin?: string) { if (origin) { return calculateHash(`${seed}+${origin}`, max); } else { return Math.floor(Math.random() * max); } }