It is not entirely random, but I vaguely recall from my time as adventurer that it's not as simple as region type or gold production.
I could be misremembering, though.
I do highly recommend trying to find a few regions where the price for one of them (or both!) is quite low, and remember to go back to these when you want to buy more...