Speaking of his trials, Job says, "But he is in one mind, and who can turn him? and what his soul desireth, even that he doeth. For he performeth the thing that is appointed for me: and many such things are with him." (Job 23:13-14)
Talking of all God's wondrous works...remembering the "marvellous works that he hath done," the Psalmist writes--
Psalm 105:17 He sent a man before them, even Joseph, who was sold for a servant:
Psalm 105:25 He turned their heart to hate his people, to deal subtilly with his servants.
The brothers of Joseph acted of their own sinful nature. When Joseph says of his brothers "But as for you, ye thought evil against me; but God meant it unto good, to bring to pass, as it is this day, to save much people alive," he is clearly talking about the same thing, not two different events. What is the antecedent of "it"? God either meant it or He didn't. Joseph says He did. If any of us say otherwise, we say differently than God's word. The best explanation is neither that God caused their actions nor that He simply knew in advance what they would do. It is that their evil, meant by them as evil, He chose to bring about good. Joseph would not have been in Egypt to deliver the sons of Jacob if they had not sold him in slavery (as well the rest of the chain of events were God's Providence that put him in the exact place at the exact time). God chose that it be so. It would not be some other way.
God is good in His means as well as in His ends. Was the brothers selling Joseph into slavery not part of God's means? Certainly he might have theoretically gotten to Egypt any number of ways. But he did not. Neither does the Bible indicate that God meant that he get there some other way. Did God wait to see what choice the brothers would make and go from there, in time? Or did He purpose from eternity what He would do?
When speaking of God there is always some element that certain things that are wrong for us according to His precepts, are not wrong for God. For example, God (as sovereign and creator) may take life/kill where we may not. Examples of this abound in the Scriptures. And there are a few times God is portrayed as "causing" something that might "seem" sinful (but is not). As Gordon Clark writes, "The Jews ought not to have demanded Christ's crucifixion. It was contrary to the moral law. But God decreed Christ's death from the foundation of the world." Or, attributing David's numbering of Israel to both God and the Devil. Or, for example, the lying of the lying prophets in I Kings 22 is attributed to the will and definitive affirmation of God.