Nothing on earth is created in vain, but rather with wisdom. Understanding this fact depends on the wisdom of people themselves. One whose faith and consequently whose wisdom and prudence increase, will happen to grasp this reasoning much better in time.
One of the most important precepts is that we are being tested throughout our whole lives. Allah tests our sincerity and our faith on different occasions. He may give favours to test whether we are grateful to Him or not. He may create difficulties, for us, to reveal whether we behave with patience or not:
“Every soul shall have a taste of death: and We test you by evil and by good by way of trial. To Us you will be returned.” (Surat al-Anbiya, 21:35)