First idea: the “sock in the drier idea.” Our minds are like spinning laundry, always turning, and which we’re always watching, and once in a while a sock or something sticks in the window and hangs there for what seems like an unnaturally long time — and that is a “random thought.”
Second idea: What seems like random thoughts are not actually random at all. A stimulus produces thought A, which results in thought B, which results in thoughts C and D, etc., but it all happens so fast we’re unaware of the logical chain. To us, the physical stimulus seems directly to result in thought D — and that relationship seems to us totally random.
Third idea is that they are mistakes. I just hit the garbage disposal switch instead of the light switch; perhaps the brain opens up the pathways to certain memories when it intended to open up certain others.