The S&P are a group of companies that have, more than other companies, stood the test of time and economic circumstances. While others have noted that there are no guarantees, these stocks offer less risk. But, less risk usually means a more conservative return on investment. Higher risk can sometimes bring higher return.
Yeah, random is not the way to go for stock-picking. It's almost like standing on a street corner and handing money to passersby, asking them to invest it and come back with the profits; you're not going to have much luck. The S&P, although you are not guaranteed anything, are at least watched and chosen by industry professionals who have a stake in the outcome.
In a sense, placing your money in a portfolio is less risky because you are spreading the risk rather than placing all of your eggs in one basket. In a portfolio, some will go up and some will go down, but hopefully your income is greater than the money you lose, and so you make a profit.
All the previous answers are very good. The key phrase in your question, it seems to me, is "at random." If the phrase had been "very carefully, after extensive research and much expert advice," I might be able to imagine that the 20 stocks could out-perform the index, although even then I suspect that they would not. Choosing stocks "at random" in which to invest would be a bit like playing Russian roulette.
To invest in a whole index is always safer, because there are risks associated with companies. For example, a company can go bankrupt. If this happens, you can lose all your money. However, if you invest in an index, you are safe by virtue of the many companies. For example the S&P 500 has 500 companies. The large amount of companies acts as protection, not to mention the benefits of diversification.
Not to mention that a portfolio that included all 500 of the S&P stocks would be guaranteed to include the top, blue chip stocks. Not that this doesn't include risk- some of the top performers this year are Sears, Netflix, and Bank of America, three companies, and stocks, that had bad years in 2011. But diversification is the main benefit.
This is because the more stocks there are in a portfolio, the more diversified you are. If some of the stocks go down, their decline is likely to be offset by a rise in the others. By contrast, it is much more possible that 20 random stocks would all go down (or that a large percentage of them would). This means the 20 random stocks are more risky.