Also, and I hope to be in topic, why do we need to try millions of hashes before finding the right one? Isn't there a way to create a mathematical way to just get the right hash on the first try?
The hashing operation basically produces a very long random number. The entire network is looking for the first random number that has a certain number of zeros in it.
It is totally random who "wins" - that is, gets the first random number with the proper number of zeros.
You make it sound as if you can just generate a random hash with a certain number of zeros in it, but this is where the nonce value comes in isn't it?
I was trying to simplify the process in order to answer the question. Here is the mining process in simple terms:
1) Hash the block
2) Check the hash and if the hash calculated matches the current difficulty (number of zeros) you win! Transmit the block to the network and collect your 25 BTC.
3) ELSE increment the nonce in the block (and/or change the block in other ways) and go to 1)
This is what is being done quadrillions of time per second 24/7 in order to secure the Bitcoin system.