It would certainly be considered illegal in some countries (France, I'm pretty sure) to have two prices at the very same moment, based on random, for the exact same product.
Do you have any idea as to why it would be illegal? In my country it's not at all unusual to see a product in a supermarket being sold at a discount price in a display at the front of the store, but at the usual price on the usual shelf.
I believe as long as it's a different physical store, it's probably possible to set a different price.
My impression (that would need more research) is that having two different prices for the same product at the same time inside the same physical store or on a website would be problematic; otherwise it's probably ok.
I think I really need to make more research - A/B pricing would definitely be interesting.