possible lossy conversion from long to int?

That’s because a long is 64 bits and an int is 32 bits, not to mention you’re going from floating-point to integer. To go from long to int, you’re going to have to discard some information, and the compiler can’t/won’t do that automatically. You’re going to have to explicitly say so through a cast: int g = (int) Math.round(Math.random() * 255); ^^^^^ … Read more

Random shuffling of an array

Using Collections to shuffle an array of primitive types is a bit of an overkill… It is simple enough to implement the function yourself, using for example the Fisher–Yates shuffle: import java.util.*; import java.util.concurrent.ThreadLocalRandom; class Test { public static void main(String args[]) { int[] solutionArray = { 1, 2, 3, 4, 5, 6, 16, 15, 14, … Read more

Creating a random string with A-Z and 0-9 in Java

Here you can use my method for generating Random String protected String getSaltString() { String SALTCHARS = “ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890”; StringBuilder salt = new StringBuilder(); Random rnd = new Random(); while (salt.length() < 18) { // length of the random string. int index = (int) (rnd.nextFloat() * SALTCHARS.length()); salt.append(SALTCHARS.charAt(index)); } String saltStr = salt.toString(); return saltStr; } … Read more