Many miners are connected to the Bitcoin network. The miners' task is to write the transactions in the blockchain, the publicly visible " ledger" of Bitcoin. Approximately every 10 minutes, a miner is allowed to create a new block and write it with the current transactions. For this, they receive a reward in the form of Bitcoin. The miner's turn is decided by random chance. You can imagine that each miner rolls the dice as often as possible. As soon as a miner has rolled a certain number, he has won and is allowed to write the transactions in the blockchain next.
Of course, a miner can't actually roll the dice like you do in the game. Instead of rolling a cube, he performs a calculation operation (hash function). This arithmetic operation includes, among other things, a random number. If the result is not what he needs, he performs the next calculation operation with another random number. As soon as the result is smaller than a certain number, he has won this round and is allowed to write the transactions in the blockchain next.