so the change as you call it is a complete randon figure or does it correspond to specific calculations or algos?
The way that bitcoin protocol works, you can't partially spend the output that you received in a previous transaction. It has to be either completely spent, or not spent at all.
So for example:
You create a brand new wallet and receive 4 transactions sending your the following amounts...
- 0.5 BTC
- 1.0 BTC
- 0.25 BTC
- 0.75 BTC
Next you choose to send 1.1 BTC to someone.
Your wallet has to choose from the unspent previously received outputs.
Perhaps it chooses the 1.0 BTC output and the 0.25 BTC output.
This supplies 1.25 in value to the transaction.
Then the wallet creates an output to send 1.1 bitcoin to your intended recipient.
This leaves 0.15 BTC unaccounted for. If the wallet does nothing more, then the 0.15 BTC is considered a "transaction fee" which the miner that confirms the transaction can claim for themselves. If you don't want to pay a 0.15 BTC transaction fee, then you need to send this "change" back into your wallet with an additional output in the transaction.