As their names were called, the candidates approached the lectern, reached into an old coffee can, and pulled out a bingo ball with a number on it. In the crowded City Hall courtroom, rival candidates and campaign managers watched eagerly, some marking down the results of a different kind of March Madness.

In Philadelphia, regardless of how many signatures candidates get or what their qualifications may be, the bingo balls in the Horn & Hardart coffee tin dictate where their names appear on election day. It can be a boost or a blow.

For State Sen. Anthony Hardy Williams, it was a boost: His name will appear first on the ballot in the May 19 Democratic mayoral primary. He and the other candidates for mayor, city commissioner, City Council, and sheriff drew ballot positions Wednesday in the ornate sixth-floor courtroom.

Williams' name will be followed on the ballot by those of former State Sen. T. Milton Street Sr., former Councilman James F. Kenney, former mayoral spokesman Doug Oliver, former Judge Nelson A. Diaz, and former District Attorney Lynne M. Abraham - assuming all stay in the race.

Ballot position typically matters less in the mayoral race because voters are more familiar with the candidates, and more in the jam-packed Council-at-large field, said Randall Miller, a history professor at St. Joseph's University who tracks the region's politics.

Still, it never hurts to be No. 1.

"I've never won any kind of lottery, so this was a great time to get my first win," said Williams, who did not attend the drawing and had an election official pull from the can for him.

The lottery will likely have the biggest impact in the Council at-large race, in which 21 Democrats are vying for five seats.

The four incumbents were not so lucky. William Greenlee drew the 15th spot; Blondell Reynolds Brown drew No. 8; Ed Neilson, who let his son pick for him, drew No. 18; and W. Wilson Goode Jr. picked the last spot, No. 21 - though he also got the last spot in the 2011 primary and still won.

Sometimes the number matters less than how names are arrayed on the ballot. In the 2011 primary, for example, there were five names per row, making Goode No. 4 in the third Democratic row.

Some challengers in 2011 received good ballot spots but lost, including educator Isaiah Thomas, who drew No. 2 that year. He's running again, and this time, his 2-year-old son, Isaiah Jr., picked him the second-to-last spot, No. 20.

"We're fine. There's no such thing as bad ballot position, only good ballot position," Thomas said.

Derek Green, a former legislative aide to retiring Councilwoman Marian B. Tasco, drew the first ballot position in the at-large race, followed by Jenné Baccar Ayers, daughter of Lloyd Ayers, a former fire commissioner.

Wilson Alexander, a community activist and 2007 Council candidate; Allan Domb, a real estate broker; and lawyer Tom Wyatt rounded out the top five.

Many candidates said they prayed before going to City Hall for the draw. Wyatt said he opted not to shave, a superstition formed in his baseball-playing days. "Now the question is, do I keep it up?" he said.

Brown drew the best position of the incumbent Council members. She also dismissed the importance of it all.

"I've pulled first and won, I've pulled last and won, I've pulled in the middle and won," she said. "So I think it's really based on your record and what voters know about you.

The process has been criticized, particularly for the impact it can have on crowded Council and judicial races.

Republican incumbents fared a little better than the Democrats. Councilman David Oh picked No. 1, and Dennis O'Brien will appear fifth in a field of seven. The City Charter guarantees two Council-at-large seats to the minority party.

In the race for city commissioner - the people who run elections - Anthony Clark, an incumbent who reportedly has not voted since 2011, received the top draw.

Dennis Lee, who used to work for Commissioner Stephanie Singer and is now running for his boss' seat, grabbed the No. 2 spot. Singer received the last spot at No. 9.

A winning strategy can also include name recognition, something former Councilman Frank Rizzo (he drew No. 19) is counting on.

Now that the positions have been drawn, primary campaigning kicks into high gear as candidates try to get their messages out and their names on powerful ward leaders' sample ballots, handed out at the polls on election day.

Those parts of the process require no luck, just a lot of money.

215-854-5506 @juliaterruso

Inquirer staff writer Claudia Vargas contributed to this article.