+ Avoid to load the welcome page by loading random ones

This commit is contained in:
Kelson42 2014-10-18 18:14:46 +02:00
parent 378c66e16c
commit 4290eaf751
1 changed files with 9 additions and 3 deletions

View File

@ -196,9 +196,15 @@ namespace kiwix {
/* Return an URL from a title*/
string Reader::getRandomPageUrl() {
zim::size_type idx = this->firstArticleOffset +
(zim::size_type)((double)rand() / ((double)RAND_MAX + 1) * this->nsACount);
zim::Article article = zimFileHandler->getArticle(idx);
zim::Article article;
zim::size_type idx;
std::string mainPageUrl = this->getMainPageUrl();
do {
idx = this->firstArticleOffset +
(zim::size_type)((double)rand() / ((double)RAND_MAX + 1) * this->nsACount);
article = zimFileHandler->getArticle(idx);
} while (article.getLongUrl() == mainPageUrl);
return article.getLongUrl().c_str();
}