Is there a way to know which chest holds the spell at the gambler?

From 40+ hours playing this game, I can pretty definitively say that it's random. The animation of the chests "scrambling" is always exactly the same and is actually just them moving up and down in a circle (and it doesn't even end smoothly). The end positions of the spell(s) or item(s) are random.

The best advice I can give for the gamblers is that there is a 2/3=66.6% chance that you won't get anything the first time, but a 2/3*1/3=2/9=22.2% chance that you won't get anything after two attempts which means there's a 77.7% chance that you will get at least something by the second try (which is a good enough deal for me).

If you're fine with those odds, then you should try for the spell/item if you like the first thing they show and you have enough gold for at least two attempts.