This passage speaks to the viewpoint we as Christians should have towards hardship and opposition. Unbelievers suffer because of doing wrong and all of us suffer sometimes because of the fallen state of the world. What the writer is saying here is that Christians are disciplined by the Lord to make them into what He wants them to be. It is training for life and how to handle it. Some of us endure greater trials because the Lord wants us to be used in greater ways or because we have sinned greatly. The unbelievers sin finds them out (Numbers 32:23) and punishes them, but God is training us.
James 1:3-5 says when you go through a trial ask for wisdom and ask God what you ought to get out of the trial (learn), not ask to get out of it. God loves us and parents ought to discipline their children too if they really love them. Trials are not to make us bitter, but better. What is God trying to teach you right now?