The 64-year-old shuffling an imaginary pack cards in the maths department at Auckland University was five when he discovered a book of magic in the attic and started doing tricks.

Persi Diaconis is still doing tricks but all those decades later they have a wider purpose than mere entertainment, entertaining though they are.

The former professional magician uses card tricks, or sometimes coin tossing, to demonstrate the "beauty" of mathematics. In New Zealand he is delivering a lecture series on how the two professions intertwine. In his world, there is literally magic in maths and maths in magic in his world

Now a professor of Mathematics and Statistics at California's Stanford University, Diaconis has used maths and playing cards to work out tricks that have fooled other magicians.

He can also use maths to detect cheating gamblers and, as a magician, has debunked so-called psychics such as Uri Geller, who took America by storm in the 1970s claiming he used his mind to bend spoons. (Just for the record, Diaconis says Geller uses not very good sleight of hand.)

Diaconis is hooked mostly, though, on randomness and probability, using mathematics to solve such concepts as how often a deck of cards must be shuffled before it is truly random.

He credits that early book from the attic - Thurston's Four Hundred Tricks You Can Do - for turning his world around.

As a youngster growing up in Manhattan with a musical Polish mother and a musical Greek father, Diaconis was a promising violinist and was accepted into the prestigious Julliard School of Performing Arts.

But what he really loved was magic. He'd practise, and cut school to go to the magic store. He and other kids would hang out at cafes where magicians gathered, until one day, along came the chance of a lifetime.

The kids sat a little apart from the magicians and this day Diaconis was practising his dealing when behind him a voice said "that's very good, I know who your teacher was."

The voice was that of Dai Vernon, one of the most respected sleight-of-hand magicians in the world.

Vernon went to sit with the other magicians, then called Diaconis over to demonstrate his dealing, which involved keeping the ace of spades at the top of the pack.

"And he said 'this kid can do that and none of you can do that', and he said 'now why don't you guys practise like that?' He said, 'son, from now on you can sit with us'."

The pair became friends and when Diaconis was 14, Vernon invited him on the road. Diaconis ran away from home to become the magician's apprentice.

They drove from city to city and Diaconis soaked up everything he could from the older man.

"And we'd hunt down crooked gamblers, because crooked gamblers are often very skilful because if they're not, you know, they get their arms broken."

Thus, Diaconis became seduced by the mathematics of gambling. A lot of the conversation with crooked gamblers revolved around probability, he says.

"Things like, what's the chance of throwing two sevens before a six and an eight. I got fascinated with how they calculate those odds and stuff like that."

One day a friend recommended he read a book on probability by William Feller which he bought, only to find he couldn't read it.

So he enrolled in night school to learn calculus and made a living as a magician by day.

When he was 17 and was out on his own, he read in a newspaper about Ed Thorp, an American mathematician who worked out you could beat black jack by counting cards, so Diaconis called him up.

He went to work with him, learnt the mathematics of counting cards and went around casinos, making money counting cards.

In his 20s, he was accepted into Harvard University and has specialised in probability theory and statistics - or the mathematics of randomness.

Diaconis has an entertaining and fascinating mind. During this interview he talks about binary and prime numbers and how they relate to shuffling cards and sometimes, due to his affability or perhaps the magician in him, I think I glimpse what he's talking about.

Well, a bit. Such as when he had a go at explaining the Riemann Hypothesis. Whole books have been written trying to explain this hypothesis to laypeople.

It's one of mathematics' so-called $1 million Millennium problems, of which there are seven.

These are problems which have eluded mathematicians and which if solved win you a cool $1 million apiece.

The Riemann Hypothesis is quite hard to explain, says Diaconis, but involves prime numbers.

The easy bit is these are numbers which can't be divided by anything except one and themselves. One question they pose, he says, is do prime numbers keep going forever or do they eventually stop?

Euclid, the ancient Greek known as the Father of Geometry, apparently proved there were infinitely many primes. But if there are infinitely many primes, how many primes are there?

"In the sense that if I go from one to 100, some of the numbers are prime. If I go from 100 to 1000 I get more primes. If I keep going up to X, where X was 100 before and then 1000, how many primes are there?"

The answer, he says, is probably X divided by the logarithm of X.

"Now, maybe that's hard and if you want to get the right answer to that question, that's equivalent to the Riemann Hypothesis."

Got it?

In other words, he explains, "a good approximation of how many primes there are up to X, that's a good equivalent to the Riemann's Hypothesis."

Aha. Um. Perhaps not surprisingly, he thinks this problem won't be solved in his lifetime, though he thinks eventually it will.

"That keeps happening; stuff that's been a mystery since the Greeks, then somebody figures it out."

Diaconis persists at trying to explain maths and does so with aplomb when describing the opening to his talk. This time I glimpse the magician's showmanship.

He walks into the room and the audience applause.

He says to them "it's natural to wonder, if you're coming to a talk that's called Mathematics and Magic Tricks, is there actually going to be any magic?"

He brings out a pack of cards, shuffles them, puts a rubber band around them and tosses them to someone in the front row.

He asks them to toss the pack to the back and the deck is thrown randomly to the back.

He asks the person who catches them to cut the cards and give them to the next person who cuts them and hands them over. This happens five times.

"I say, 'now this is going to sound strange in an academic environment but I want everybody to look at their card and concentrate on that".

Academics usually burst out laughing at this.

He tells them they're doing a great job concentrating but he's getting a jumble of information, so would everyone with a red card stand up because he sees red in his mind better than black.

People with red cards stand up.

"Now, let's see," he says, "you've got a red card - it's a heart isn't it? Seven of hearts?" He names all the cards and gets them right.

"And the thing is, that's quite a good trick because I can't see the cards often and it seems somehow spooky."

But it's just maths.

He's obtained some information from the participants, such as how many people had a red card.

From there, he can work out the different possibilities of how the deck of cards played out as it was cut.

"It turns out the deck is arranged so that every possible combination occurs exactly once and there are 32 cards handed out and so their pattern codes to me which way it's played out. "So that's a very nice trick, right? And it's a trick that fools magicians because they just can't imagine, they think I have X-ray glasses on or stooges behind, you know, the people who signal the cards."

Though this might all seem to be trickery, there are serious applications. Diaconis explains about De Brujin sequences which relate to card patterns but which are used in many different areas, from "smartpens" which record on special paper containing unique patterns, to reading DNA, to cryptography (the way spies talk to each other) to how your credit card works.

Ah, I say, having the smallest of eureka moments, this is what you mean by the beauty of maths?

He smiles. Maths is not only beautiful, he says, it's useful too.