Skip to content

Commit de4f189

Browse files
committed
Added random hashing to library
Uses Math.rand class to make 16 random values converted to hex.
1 parent 0c33c87 commit de4f189

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.redomar.game.lib;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
5+
public class HashGen {
6+
7+
private String hexHash;
8+
private boolean prefix;
9+
private int hexLength;
10+
11+
public HashGen(boolean showPrefix, int length){
12+
this.prefix = showPrefix;
13+
this.hexLength = length;
14+
init();
15+
}
16+
17+
private void init(){
18+
if(prefix){
19+
hexHash = "0x";
20+
} else {
21+
hexHash = "";
22+
}
23+
}
24+
25+
public String getHash(){
26+
setHash(hexLength);
27+
return hexHash;
28+
}
29+
30+
private void setHash(int hexLength){
31+
32+
String hex;
33+
34+
for (int i = 0; i < hexLength; i++){
35+
hex = Integer.toHexString(randNumGen());
36+
hex = StringUtils.capitalize(hex);
37+
hexHash = hexHash + hex;
38+
}
39+
40+
}
41+
42+
private int randNumGen(){
43+
int rand = (int)(Math.random() * 16);
44+
return rand;
45+
}
46+
}

0 commit comments

Comments
 (0)