The best selling Scottish author Ian Rankin has revealed how he nearly became a suspect in a crime as he undertook research his debut Rebus novels.

Speaking at the Hay Festival, he told the audience how he once told police officers the plot for his first detective novel, Knots and Crosses, published in 1987, but it was so similar to a real case the police were working on that he was questioned.

He said: "I gave them the plot of Knots and Crosses not realising it was very similar to a case they were investigating.

"They took me into an interview room, actually turned on the computer, too my details and entered them in the data-base."

He added: "I went home and thought 'that was a bit odd they were interviewing me, I thought I was interviewing them.'

"And my dad said: 'you silly bugger.

"At that point I was the only suspect they had."

Rankin said he was reminded of the incident because he thinks real life is currently stranger than fiction.

At the annual literary festival he added: "The real world is full of wild, outlandish coincidences that we can't use because fiction has to be realistic.

"There's nothing realistic about the world now, politics-wise, everything-wise. You couldn't make it up - it's a problem for fiction writers."

Last year Rankin revealed at the Edinburgh International Book Festival that the head of Police Scotland had met with a group of crime writers to explain changes in the force.

"I shouldn't be telling you this, the Chief Constable did have quite a lot of crime writers in for a meeting," he told the audience.

"We said 'Look this is a nightmare,' and he said, 'Well, look this has all been done for the right reasons and I sure you can find a way round it' and 'It will freshen up the prose' and 'You must be getting jaded, Ian - surely you want to do something different'.

"So that's been a huge change, and trying to explain that to readers all over the world, for most of whom it is an inconvenience, trying to explain that has happened, without boring them with the detail of that, is quite tough."

Mr Rankin said the operational changes had vexed the nation's crime writers and also, in his fiction, made Rebus a figure whose methods are increasingly outdated.

He said: "The way policing is structured has changed so much in Scotland in the past few years.

"We have this thing for Police Scotland, and for crime writers, any crime writer who comes on this stage will tell you how horrified we were when the change took place."