I want to generate a random number between 1 & 97, then message the player: ChatColor.RED + "Your ID is" + ChatColor.GREEN + the random number How would I do that?
Code:java Random rnd = new Random(); int yourId = rnd.nextInt(97) + 1; //nextInt() will return a sudo-random number from 0 to # - 1
I wouldn't depend on that if you're assigning IDs to players, as it's extremely likely to repeat itself. You'd need to make sure each player had a unique ID.
Why not just, Code:java int random = ((int) Math.random() * 97) + 1;player.sendMessage(ChatColor.RED + "Your ID is " + ChatColor.GREEN + Integer.toString(random))
Code:java SecureRandom sr = new SecureRandom();UUID uuid1 = UUID.randomUUID();String uuids = uuid1.toString();int length = uuids.length();StringBuilder sb = new StringBuilder(uuids);for (int x = 0; x <= length/2; x++){length = sb.length();sb.deleteCharAt(sr.nextInt(length));sb.reverse();}String s = sb.toString();s = s.replaceAll("-", "");return s; Is what I use if I want a REALLY random id. It's really resource intensive, but it's probably the most random string you're going to get.