Though it may seem that many things happen by chance, because we don't know the causes, nothing happens without a cause. That's not fatalism either, but conditionality. When past kamma bears fruit, we can react to it in different ways — making fresh wholesome or unwholesome kamma that will bear fruit in the future. If it was not possible to change our destiny by modifying our present kamma, then the Buddha would not have bothered to teach the Dhamma.
If we think lustful thoughts it is the unwholesome mental kamma of covetousness (abhijjhā), and that has consequences. Old habits die hard, so the more that we follow unskilful thoughts, the more vulnerable we are to following unskilful speech and action when conditions conspire to make it likely.
The Sutta in question gives methods how to replace unwholesome reflections with wholesome ones.
A certain monk was in the habit of contemplating bones in the cemetery. One day, while walking for alms, he met a woman on the road who had left the house, having quarrelled with her husband. On seeing the monk, she entertained wicked thoughts, and laughed. The monk looked up, but instead of seeing a beautiful woman and being overpowered by lust, all he saw was a skeleton walking along the road. He then gained Arahantship. What do you think would have happened if the monk was in the habit of entertaining lustful fantasies?