How would you define gambling? Would it make trading stocks illegal?
If it is based on chance, then it is gambling.
Until the Commodity Futures Modernization Act of 2000, Collateral Debt Obligations were regulated differently in different states. Some said it was insurance, and thus regulated it like insurance. Some said it was gambling and banned it outright. Instead, regulation was handed to a toothless new agency who got little funding for enforcement and the rest of the world got the 2008 financial crisis.
https://en.wikipedia.org/wiki/Commodity_Futures_Modernizatio...
Lots of countries have managed to legally define gambling and ban it without making stock trading illegal. Even the US. This isn't some gotcha.