Job was a righteous man who suffered greatly. His children were killed and all his possessions were taken from him. Then he suffered a painful disease, nearly to the point of death. We learn from the story of Job that good things happen to bad people and bad things happen to good people. Why is this?
James, Chapter 1:2-6, gives us the answer:
Consider it pure joy, my brothers and sisters whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.
If any of you lacks wisdom, you should ask God, who gives generously to all without finding fault, and it will be given to you. But when you ask, you must believe and not doubt, because the one who doubts is like a wave of the sea, blown and tossed by the wind.