People often say destiny is prewritten on the contrary people also say that we write our own destiny. It's interesting to debate to know which one is true, however, I will explain here my perspective and try to evaluate which one makes more sense to me.
An algorithm is a set of rules, which quite often we use in computer programming, where we write a command to perform a certain routine task, for example, if I write a computer program say you have to execute a file at morning 8 am daily, the computer will follow this timeline and trigger this command every day at 8 am and a file will be sent.
In our day-to-day life, we come across many things and we act upon those things based on our understanding or past experience, it's quite possible two different people will react to the same situation differently as they have different exposure.
Since there are billions of people on this planet and every second there are billions of things that take place it's next to impossible to monitor each one's activity and evaluate whether things are done in a correct manner or not.
In my opinion, God has written an algorithm to evaluate each and every small thing and the rest is up to us how we react to each situation and the consequences of that reaction will decide our fate. There is a famous saying that every action has its reaction similarly we will be punished or blessed for every act we perform the only difference would be the timing when will be blessed or punished for an action.
Many a time we think about why this is happening to us, but we don't remember in the past what we have done and the consequences of that we are suffering now, the theory of Karma emphasizes the same thing, you are rewarded for your own deed.
I would like to conclude by saying that God has written an algorithm that evaluates and accordingly we write our own destiny.