// Set the desired hit chance (e.g., 20%)
int hitChancePercentage = 20;
// Generate a random number between 1 and 10
Random random = new Random();
// Generates a number between 1 and 10
int randomNumber = random.nextInt(10) + 1;
// Calculate the range based on the percentage
int maxHitNumber = (int) Math.ceil(hitChancePercentage / 10.0);
// Check if the random number falls within the hit chance
if (randomNumber <= maxHitNumber) {
System.out.println("Hit! Random number: " + randomNumber);
} else {
System.out.println("Miss. Random number: " + randomNumber);
}