From 4290eaf751dbf31de975e19636a770dfd8572851 Mon Sep 17 00:00:00 2001 From: Kelson42 Date: Sat, 18 Oct 2014 18:14:46 +0200 Subject: [PATCH] + Avoid to load the welcome page by loading random ones --- src/common/kiwix/reader.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/kiwix/reader.cpp b/src/common/kiwix/reader.cpp index d1b5c0eab..7dfb2afed 100644 --- a/src/common/kiwix/reader.cpp +++ b/src/common/kiwix/reader.cpp @@ -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(); }