Are you sure that you have 2000 topics? Or is that only the maximum number?
You would need to know the maximum number of topics for the random generation number to work between the range. So, in the expression:
topicnum = Math.round(Math.random()*(topiccount-1))+0;
"topiccount" must be the maximum o available topics.