hey guys i need some assistance i tried a few ways of doing this but i never applied chance to anything before i tryed Random as u can see and it makes a Wooden Sword with the name "Wooden Sword" or it makes the first one "test1" but non of the others. what im hoping for is someone can help with what i did wrong or knows how to make it so out of 100% test1 has a 60% chance to be made test2 has a 30% chance to be made test3 has a 10% chance to be made something along those lines Code:java @EventHandlerpublic void onCraft(CraftItemEvent event) { Random random = new Random();int randomNum = random.nextInt(99) + 1;if (randomNum <= 60) { ItemStack woodensword = new ItemStack(Material.WOOD_SWORD, 1);ItemMeta item = woodensword.getItemMeta();item.setDisplayName("test1");woodensword.setItemMeta(item);event.getInventory().setResult(woodensword); } else if (randomNum <= 30) { ItemStack woodensword = new ItemStack(Material.WOOD_SWORD, 1);ItemMeta item = woodensword.getItemMeta();item.setDisplayName("test2");woodensword.setItemMeta(item);event.getInventory().setResult(woodensword); } else if (randomNum <= 10) { ItemStack woodensword = new ItemStack(Material.WOOD_SWORD, 1);ItemMeta item = woodensword.getItemMeta();item.setDisplayName("test3");woodensword.setItemMeta(item);event.getInventory().setResult(woodensword);}}} Thanks in advance Bless_
First, nextInt() is between 0 and max number exclusive, therefore you have generated a 0 to 98 number, which makes 99 options... set it to 100. Next, you've used the wrong order of conditions... the first one will overwrite all other cases because 30 and 10 are both smaller than 60, check them starting with lowest. Also, you've got duplicated code there... I suggest you get the duplicated code out of the conditional statements and only place there what will change due to chance.