Despite criticism, a federal program that awards U.S. permanent residency to foreigners through a lottery has been around for almost 30 years. This is how the lottery works.