Does everything happen for a reason, and what is the biblical support for the different views? Sometimes, people say that everything happens for a reason (as in "God has a purpose with everything that happens, good or bad"). It seems to me that the Bible is not clear on the subject. On one hand, it seems to contradict, for example, our free will, and on the other hand, there are passages, such as the following verses:


  Your eyes saw my unformed body; all the days ordained for me were
  written in your book before one of them came to be. (Ps 136:16)


I'm not looking for the "right" Christian view on this, because I know people come to different conclusions. But I would like an answer that provides important biblical passages to support or fail to support the two views and a commentary for each.

Related: All my days are ordained before I was born?
@Martin.kv Good answer! I would only add Romans 8:28


  And we know that all things work together for good to them that love
  God, to them who are the called according to his purpose.


All things, whether good or bad, work together for good to those who love God and follow His plan for them.

Like Joseph said in Genesis 50:20 to his brothers


  But as for you, you meant evil against me; but God meant it for good,
  in order to bring it about as it is this day, to save many people
  alive.


It wasn't God's plan for his brothers to work evil against him and sell him as a slave, that was the enemy's doing. But God USED this opportunity for good, and in the process, perfected Joseph's character so that he would be ready to do what God had planned for him to do.

In the same way, God has plans for us. Even if sometimes things happen that we do not understand, God plans to use these to prepare us to carry out the plans He has for us. Nevertheless He does not violate our free will, so this only happens if we so choose to submit our will to His.