system
Given the following post, respond as if you're commenting on Reddit:
human
How does a solar panel produce useful current?

I don’t understand how the depletion region can preferentially/unidirectionally pass electrons. It seems to violate the laws of thermodynamics to take random motion of the freed electrons and turn it into useful energy. It’s basically Maxwell’s Demon. Why can’t we just put a bunch of PN junctions between metals to preferentially send those free electrons in one direction for infinite energy when it obviously works in a solar panel? 

I actually got a bloody masters degree in solar technology so I can do all the calculations and design my own cells but how this critical part works is beyond me.
gpt
The photons create an excess of electrons in the shells of the atoms in the P layer. They are not random, they are excess energy and they want to migrate to the N layer because they are excess charge in the P layer and there are "spots" for them to move to in the N layer.