President Trump railed against the diversity visa lottery program and chain migration Friday, saying that immigration officials are choosing the “worst of the worst” to enter the United States.

The president, who was speaking to the graduating law enforcement officers from the FBI National Academy in Quantico, Virginia, pointed to two recent terror attacks.

On Monday, Akayed Ullah attempted to carry out a mass-casualty terror attack in a New York subway, but the bomb’s detonation resulted only in serious injuries to the Bangladeshi green card holder who came to the United States in 2011 on a visa available to nieces and nephews of U.S. citizens. Three people sustained minor injuries in the terror incident.

At the end of October, Sayfullo Saipov mowed down people on a New York City bike path with a rented Home Depot truck, killing eight and injuring 11 others. The 29-year-old came to the U.S. in 2010 from Uzbekistan through the visa lottery program.

“Both terrorists came to our country through the dysfunctional immigration system that we are correcting, rapidly. And one came through chain migration. Chain migration. The other visa lottery,” Trump said.

“You think the country is giving us their best people? No,” he added, referencing the lottery program. “What kind of a system is that? They come in by lottery. They give us their worst people, they put them in a bin, but in his hand when he’s picking him are really the worst of the worst.

“Congratulations, you’re going the United States, ok? What a system,” he continued.

Pres. Trump criticizes immigration visa lottery program: "They give us their worst people, they put them in a bin, but in his hand when he's picking them is really the worst of the worst...What a system." pic.twitter.com/gNvYIpnfwK — Evan McMurry (@evanmcmurry) December 15, 2017

The program, initially created to diversify immigrant flows, offers a lottery for up to 50,000 visas per year. It became permanent in 1990 as part of a bill Senate Minority Leader Chuck Schumer, then a member of the House, introduced. The bill had bipartisan support and was signed into law by former President George H.W. Bush.

Applicants, who must pass a background check, need to have a high school-level education or job experience that involves two years of training. Out of the lottery winners the U.S., not foreign countries, choose (and can refuse) visa recipients.

Since 2007, the State Department said nearly 30,000 visas have been given to people from nations designated as state sponsors of terrorism: Sudan, Syria, and Iran.

“We’re calling for Congress to end chain migration and to end the visa lottery system and replace it with a merit based system of immigration,” Trump said. “We want a system that puts the needs of American families, taxpayers, and security first."