Generate Convex polygon from random vertices

Hello,

I have a problem that is not totally specific to blender but the soultion I find will be implemented into my blender project. Is there a known algorythm for sorting a bunch of random vertices into a cetain order to make a convex polygon?

Thanks in advance.