"Have sex with an immigrant," Nanjiani told the graduates of Grinnell College in Iowa during a commencement speech. "We're going through a tough time right now, and it would just be really great for morale."
Nanjiani graduated from the liberal arts school in 2001. Grinnell invited him back this week to deliver the commencement address to the graduating class of 2017. During the ceremony, the school awarded Nanjiani an honorary Doctor of Humane Letters.
The star of HBO's "Silicon Valley" opened up to the graduates about his experience moving from Pakistan to Iowa for college and how it shaped the way he moved through the world.
"When I came to Grinnell I was a devout Muslim who had never romantically touched a girl and I was going to get a degree that guaranteed me a job," Nanjiani said. "By the time I graduated I was basically a Rastafarian with a white American girlfriend and a philosophy degree. College changes you, is my point."
He also offered advice on how to take on bigotry, even if it is uncomfortable.
"We cannot expect others to understand our point of view if we don't understand theirs," he said. "It's uncomfortable and awkward and infuriating and it hurts your brain, but with that pain can come growth and real change."
"Being a fish out of water is tough, but that's how you evolve," he added. "I think that's scientifically accurate — I don't know, I had a liberal arts education."
Nanjiani advised the graduates to live with intention and not fear failure ― unless, he joked, you're the person who created the exploding Samsung Galaxy phones.
"I never thought big picture," Nanjiani said. "That would have overwhelming. So what I'm saying is, you can go slow. Allow your dreams and goals to change, but live an intentional life."
He continued: "Here's the big secret I've learned in the last few years: Nobody knows what they're doing ... Everybody's winging it out there. Some people are just better at pretending to be confident because nobody's done ― nobody's cooked."
Watch Nanjiani's full commencement speech below.