Ahead of the series finale for the hit television show The Big Bang Theory, Canadian musician Ed Robertson shares how he came up with the catchy theme song while he was barenaked in the shower.

The legendary frontman for the Canadian alternative rock band Barenaked Ladies said it was a twist of fate that brought the group and the long-running sitcom together.

Twelve years ago, Robertson said he and the band had no idea famed television writers Chuck Lorre and Bill Prady were in the audience at one of their L.A. concerts.

Coincidentally during that show, the self-proclaimed 鈥渟cience nerd鈥 says he performed a freestyle rap about the Earth鈥檚 origins, inspired by Simon Singh鈥檚 book 鈥楤ig Bang: The most important scientific discovery of all time and why you need to know about it.鈥

鈥淚 was just making up a silly song about the astronomer Hubble and standing on the shoulders of giants and cosmological theory and Billy Prady and Chuck Lorre were at the show and that鈥檚 what made them think that they had to get me to write their theme song for the show,鈥 he told CTVNews.ca during a telephone interview on Wednesday.

鈥淚t all came to me in a flash鈥

Robertson admitted he was initially hesitant to accept their offer because he had written music for films and television shows in the past, but they were never picked up. And to top it off, he was feeling 鈥渂urnt out鈥 from touring. He credits his wife with persuading him to embrace the opportunity.

鈥淚 told her 鈥業鈥檓 supposed to do this conference call for a television theme song, but I haven鈥檛 written it so I think I鈥檓 just going to get on the call and let them know that they need to find somebody else鈥 and my wife said 鈥榃ell, who鈥檚 it for?鈥 and I said 鈥楽ome guy named Chuck Lorre鈥 and she said 鈥楥huck Lorre? You should probably Google him,鈥欌 he said with a laugh.

Minutes later, Robertson said the lyrics for the song just came to him while he was in the shower.

鈥淚 had to call my wife in. It all came to me in a flash. I had to call her and say 鈥楥an you write this down before I forget it?鈥 [I had] shampoo in my face,鈥 he recalled.

Afterwards, he recorded the song on his computer and sent it to Lorre and Prady.

鈥淭hey loved it,鈥 he said.

Since then, that covers everything from the Neanderthals to Einstein has become a staple in the Barenaked Ladies鈥 set list, even landing a spot in the band鈥檚 greatest hits album 鈥淗its from Yesterday & the Day Before鈥 in 2011.

鈥淚 would say when the show aired, I never anticipated that we鈥檇 be playing this song live,鈥 Robertson said. 鈥淚f we play four songs it鈥檚 going to be 鈥淥ne Week,鈥 鈥淚f I Had a Million Dollars,鈥 鈥淧inch Me,鈥 and 鈥淭he Big Bang Theory,鈥 the rest can rotate in and out.鈥

Sitcom success

As for whether the band鈥檚 proceeds from the theme song have finally allowed him to buy a fur coat, a monkey, and Kraft Dinner -- as per their hugely successful song 鈥淚f I Had a Million Dollars鈥 -- Robertson said he would have bought those things if it wasn鈥檛 for his wife鈥檚 sensibilities.

鈥淚t鈥檚 been very good to me,鈥 he said.

The television show has also been very good to the Barenaked Ladies in the years since its premiere, Robertson said.

鈥淭hey had us down for their 100th episode taping and we performed for their live audience. It鈥檚 just been a really good relationship,鈥 he shared.

As for how he feels about the show鈥檚 final episode airing Thursday night after 12 seasons, Robertson described the emotion as bittersweet.

鈥淚n some ways it鈥檚 sad that it鈥檚 ending, but it鈥檚 also really great that it鈥檚 going out on top where nobody鈥檚 sick of it and it鈥檚 a perfect time to wrap it up,鈥 he said.

For fans who will miss the familiar fast-paced theme song at the start of every episode of The Big Bang Theory, Robertson said the Barenaked Ladies have several tours planned where the tune will inevitably make an appearance.

鈥淲e鈥檝e got a 50-show tour of America starting at the end of this month. U.K and Canadian tours in the works. A new record in the works. It never stops,鈥 he said.

The final episode of The Big Bang Theory airs Thursday, May 16 at 8 p.m. ET/PT on CTV, CTV.ca and the CTV app.