>>9284953This depends on the coin, but generally speaking the "hard problems" that need to be solved are generated by the use of the coins.
So, let's take Bitcoin. Every time a coin changes owner, the change is announced to the network. Nodes in the network then pack together several of these transactions with some additional info (like a timestamp) and run it through a hash function (a hash function is something that given an input generates a fixed-size string of characters as an output). Hash functions are not computationally expensive to calculate (that is, given an input it generates an output quickly), but they are almost impossible to reverse (that is, given an output it's almost impossible to determine what the input was) however the challenge resides in generating a hash starting with a certain amount of 0s (the more starting 0s needed, the harder the problem).
So how can a node get a hash with the required number of 0s? Well, inside the block of transactions there is a special place for something called the Nonce. The nonce is just a value that can be anything. Nodes then have to try out different values for this Nonce until the generated hash has the necessary number of 0s at the start. When they manage to do it, they broadcast the hashed block to the rest of the network. The reward for being the first one to achieve it is "mining" a new coin (the mining of the coin itself is actually just another transaction in the transaction block declaring the miner the owner of a coin). Each block also contains the hashed previous blocks, that way the whole transaction history of the network is preserved.
So we cannot run out of problems, because the operation of the network itself is the problem. In the case of Bitcoin we will run out of new coins to mine, though, as the maximum number of coins is finite by design (to avoid inflation).