Topic: How HELP's !random works...
Sometimes ppls think !random is just unfair. All i can do is sharing the code how the command works.
The command itself:
/**
* Random command
*
* @return boolean
*/
private boolean cmdRandom() {
if (!hasCommand("random") || char_ != '!') return false;
int max = 1000;
String seps = ",\\.\\-\\|\\:\\/\\\\\\# ";
String string = param1+' '+param2+' '+param3+' '+message;
Matcher matcher;
Map<Integer,String> map = new HashMap<Integer,String>();
ArrayList<String> players = new ArrayList<String>();
// Max value
matcher = regInteger.matcher(string);
if (matcher.find()) {
max = Integer.parseInt(matcher.group(1));
string = string.replace(matcher.group(1),"");
} else max = 1000;
string = string.replaceAll("[ ]+"," ").trim();
// List of players
matcher = Pattern.compile("([a-zA-Z"+seps+"]+)").matcher(string);
if (matcher.find()) {
String[] split = matcher.group(1).trim().split("["+seps+"]+");
for (String p : split) {
if (!p.isEmpty() && !players.contains(p.toUpperCase())) players.add(p.toUpperCase());
}
}
// Random
if (players.size() > 0) {
for (String p : players) map.put(Utility.Random.Integer(0,max),p);
List<Integer> rnds = new ArrayList<Integer>(map.keySet());
Collections.sort(rnds,Collections.reverseOrder());
string = "";
for (Integer rnd : rnds) string += " "+map.get(rnd)+": "+rnd;
draw(lng.get("%0 randoms for [%1]...%2",player,max,string));
} else draw(lng.get("%0 randoms [%1] and gets a [%2]",player,max,Utility.Random.Integer(0,max)));
return true;
}
The Utility.Random.Integer(int min,int max):
/**
* Integer
*
* @param min
* @param max
* @return int
*/
public static int Integer(int min, int max) {
return min + (int)(Math.random() * ((max - min) + 1));
}
Math.random() is an internal java thing, i have no control on that. I also dont set any kind of seed or whatever would change the behavior of that method.
PS: Feel free to post a better algorithm if you can
Cisco T4 Sco 90
Delphi T1 Eng 21
Neuropath T0 Tel 10