Do you mean to a weapon or to the player itself (as in a buff)?
On the weapon it's easy, you can override the ConsumeAmmo function of the ModItem and just check against a random value. As an example:
Code:
public override bool ConsumeAmmo(Player player)
{
if (Main.rand.Next(0, 2) == 0) // 50% chance not to consume ammo.
return false;
return true;
}
If you want it on the player, you'll either need to wait for player hooks (I guess you'll be able to do it then) or use one of the build in booleans from the player, but these are hardcoded at set percentages.