From 84e220b332bfffb0f2dcc39b9697a6fd6691d265 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Mon, 25 Apr 2022 18:36:30 +0200 Subject: Initial commit --- src/misc/Utils.java | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 src/misc/Utils.java (limited to 'src/misc/Utils.java') diff --git a/src/misc/Utils.java b/src/misc/Utils.java new file mode 100755 index 0000000..a3d5b0a --- /dev/null +++ b/src/misc/Utils.java @@ -0,0 +1,73 @@ +package misc; + + +import java.io.UnsupportedEncodingException; + +public class Utils { + + public static int randomInt(int from, int to) { + return (int) (from + Math.round(Math.random() * to)); + } + + public static String randomStringAN(int length) { + String output = ""; + char[] table = new char[] { + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' + }; + for(int i = 0; i> 24) & 0xFF), + (byte) ((a >> 16) & 0xFF), + (byte) ((a >> 8) & 0xFF), + (byte) (a & 0xFF) + }; + } + + public static int byteArrayToInt(byte[] b) + { + return b[3] & 0xFF | + (b[2] & 0xFF) << 8 | + (b[1] & 0xFF) << 16 | + (b[0] & 0xFF) << 24; + } + + public static byte[] intTobyteArray(int a) + { + return new byte[] { + (byte) ((a >> 24) & 0xFF), + (byte) ((a >> 16) & 0xFF), + (byte) ((a >> 8) & 0xFF), + (byte) (a & 0xFF) + }; + } + +} -- cgit v1.2.1