line intersection detection

I am drawing random polygons in a program and I need to detect when there will be an intersection of two lines. Does anyone have a good idea of how to do this? And if possible, can it be better than 2^n? Thanks