package utils;

class StringUtils {
	/*
		returns a random string of n characters with Hex chars (0123456789ABCDEF)
	 */
	static public function getRandomHexString(pStringLength:Int = 8) {
		{
			var chars:String = "0123456789abcdef";
			var rndString:String = "";
			for (i in 0...pStringLength)
				rndString += chars.charAt(Math.round(Math.random() * chars.length));
			return rndString;
		}
	}

	/*
		returns a random string of n characters within ASCII visible chars range (33 ! -> 126 ~)
	 */
	static public function getRandomStringFromASCII(pStringLength:Int = 8):String {
		var rndString:String = "";
		for (i in 0...pStringLength)
			rndString += String.fromCharCode(Math.round(Math.random() * 93) + 33);
		return rndString;
	}

	/*
		returns a unique id
	 */
	public static function generateUID():String {
		var s1:String = StringUtils.getRandomHexString(8);
		var s2:String = Std.string(Date.now().getTime());

		return s1 + s2.substr(s2.length - 4, 4);
	}

}
