NEW YORK — The lottery began with a roll of dice in a conference room steps away from the pastor’s office.

The number that came up, five, determined how many times Joseph V. Dorsa, director of finance and operations at St. Andrew Avellino Roman Catholic Church in the New York City borough of Queens, would run a computer program to scramble the 923 names on the church roster and display them in random order.

Then, and only then, would Dorsa look to see whose name had come up first, and the pastor, the Rev. Joseph T. Holcomb, would call and offer that person two tickets to the Mass that Pope Francis will celebrate Friday at Madison Square Garden.

With the pope’s arrival days away, there have been a lot of lotteries. Faced with far more demand than supply — demand fueled by Catholics hoping for a glimpse of an intriguing and charismatic pope who is making his first visit to New York — most Catholic parishes in the city resorted to drawings to distribute the small number of tickets they had been allotted for the Mass.

The several hundred priests chosen as concelebrants for the Mass, where they will join in the celebration of the Eucharist, were picked by lottery. The 250 middle-school students who will greet the pope when he visits East Harlem were chosen by lottery. And the city organized its own lottery for tickets to the pope’s procession through Central Park.

The city received 93,143 ticket requests — 84,023 from people who completed an online form, the rest from callers to 311. A computer program then chose the recipients for 40,000 pairs of tickets.Inevitably, tickets to the Central Park event — free from the city — turned up for sale on websites like Craigslist and eBay. Some were being offered for as much as $500 apiece.

A papal visit always seems to captivate the city, but Francis’ trip to New York is shaping up as an even bigger draw, in part because his engaging and humble tone has made him enormously popular.

But with 9.2 million Catholics in the city and surrounding suburbs, opportunities to see this pope are far more limited than they were for his predecessors. Pope Benedict XVI said Mass to 60,000 at Yankee Stadium in 2008. Pope John Paul II drew a crowd of 120,000 for a Mass in Central Park in 1995.

For the Mass at Madison Square Garden, Francis’ largest New York event, the arena’s seating capacity will be about 20,000, said Joseph Zwilling, a spokesman for the Archdiocese of New York. A visit to Philadelphia is the centerpiece of the pope’s six-day trip to the United States, which will begin in Washington.

“The reality is, it’s smaller than we’ve had in the past,” Zwilling said of the papal visit to New York. “The Archdiocese of New York and the Archdiocese of Washington said, ‘We don’t want to do anything that would be too big because we want the main attention to remain on Philadelphia.’”

Only 2,400 to 2,500 ticket-holders, all of them members of the clergy, will attend the first public event on the pope’s schedule in New York, vespers at St. Patrick’s Cathedral on Thursday night. That total includes about 300 extra seats that are being squeezed in for the occasion.

The deans of colleges in the archdiocese and priests who serve on councils and archdiocesan committees were promised tickets for vespers, and retired priests were also invited. “That pretty quickly fills up the cathedral,” Zwilling said.

Increasing the count a bit, 500 people will be allowed onto the steps at St. Patrick’s when the pope’s motorcade pulls up.

For the pope’s visit to the National September 11 Memorial on Friday, Zwilling said, the memorial held a lottery for 1,000 tickets for admission to the plaza. Those went to relatives of people killed in the Sept. 11 attacks on the World Trade Center and to survivors, rescue workers and people who lived nearby. Francis will then enter the National September 11 Memorial Museum for a “multireligious gathering” with 400 to 500 leaders from other faiths.

After lunch, the pope will visit Our Lady Queen of Angels School on East 112th Street, where 250 middle school students will be waiting outside and 12 high school seniors will be waiting in the hallway as the pope is led to a classroom with 24 third- and fourth-graders from four Catholic schools.

The timing of Francis’ arrival figured in which students were chosen.

“They’re going to be in the classroom waiting for more than an hour” before the pope walks in, said Fran Davies, a spokeswoman for the archdiocese’s schools, so the advantage went to children whose teachers felt they could stay still.

Francis will meet another relatively small group in the school’s gymnasium: about 100 people, many of them immigrants, who have received assistance from Catholic Charities.

As for the Mass at the Garden, Zwilling said, “the greatest number” of tickets had been distributed through local parishes. Those in Manhattan got allotments based on attendance figures at Sunday Mass, with a minimum of five tickets per parish. “If you had a large number for Mass attendance,” he said, “you’d get more.” Tickets also went to neighboring dioceses like the Diocese of Brooklyn, which promised each parish two tickets and left it to pastors or parish administrators to decide how to distribute them.

At St. Andrew Avellino, Holcomb explained what he called “the parameters” at Mass last week — that the day of the Mass at the Garden would be a long one for worshippers, who would have to arrive hours before the service began.

Also, whoever was chosen had to be reachable by telephone Monday morning, when the drawing was held. As Joseph Brostek, the church’s unofficial historian, put it, “If there is no answer, they’ll go to the next person on the list.”

It was Brostek who rolled the dice.

The first name to come up belonged to Ofelia Norico, a longtime congregant who is a Eucharistic minister, a layperson who assists with Masses and visits to parishioners unable to get to church. Answering on the third ring, Norico said she was surprised she had been chosen, and asked her sister-in-law, Carmelita Norico, who sings in the church choir, to join her.

Holcomb applied to serve as a concelebrant at the Garden Mass, but even if he is not given that responsibility, he will see the pope in Washington. He has a ticket for a Mass at the National Shrine of the Immaculate Conception on Wednesday at which the pope will canonize the Rev. Junípero Serra, an 18th-century missionary who brought Christianity to Baja California.

“What Francis represents and, more importantly, how he has lived out the papacy is certainly different than what we’ve experienced before,” Holcomb said. “Francis, in the audience at the Vatican, took like a soda or a coffee from one of the pilgrims in Vatican Square and drank from the straw. We watched it on the big Jumbotron. There seems to be a spontaneity, and a level of trust — whatever was in that cup, he was trusting enough that it was not going to harm him.”