When someone buys shares of stock something real -- partial ownership of a company -- is being transferred from one person to another. Those shares mean something, and anyone can read the prospectus to see what exactly those shares mean. Companies pay dividends, buy back shares, and allow shareholders to vote on who will lead the company and what the company should do. When a company is bought by another company the shareholders are paid. In theory the shareholders might receive some proceedings from a bankruptcy proceeding (in practice this is uncommon since the creditors have to be paid first and usually bankruptcy happens when debts can no longer be paid in full).
There is more than just random numbers involved. Equity prices may have a tenuous connection to reality, but there is some real-world basis for stock, bonds, and derivatives. That is what separates financial markets from casino games (which are purely random number games).