// Taken from KApplication
std::string random_string(int length);
+
+ /** Return a random number from <tt>[0,RAND_MAX[</tt>. */
+ inline unsigned random()
+ {
+ return random_int();
+ }
+ /** Return a random number from <tt>[0,size_r[</tt>. */
+ inline unsigned random( unsigned size_r )
+ {
+ return random_int() % size_r;
+ }
+ /** Return a random number from <tt>[min_r,min_r+size_r[</tt>. */
+ inline unsigned random( unsigned min_r, unsigned size_r )
+ {
+ return min_r + random( size_r );
+ }
+
+
} //ns base
} // ns zypp
#include <fstream>
#include "zypp/base/Logger.h"
#include "zypp/base/Gettext.h"
+#include "zypp/base/Random.h"
#include "zypp/Digest.h"
#include "zypp/SourceFactory.h"
#include "zypp/source/SourceImpl.h"
IMPL_PTR_TYPE(SourceImpl);
-// Taken from KApplication
-static int random()
-{
- static bool init = false;
- if (!init)
- {
- unsigned int seed;
- init = true;
- int fd = open("/dev/urandom", O_RDONLY);
- if (fd < 0 || ::read(fd, &seed, sizeof(seed)) != sizeof(seed))
- {
- // No /dev/urandom... try something else.
- srand(getpid());
- seed = rand()+time(0);
- }
- if (fd >= 0) close(fd);
- srand(seed);
- }
- return rand();
-}
-
-// Taken from KApplication
-static std::string randomString(int length)
-{
- if (length <=0 ) return std::string();
-
- std::string str;
- str.resize( length );
- int i = 0;
- while (length--)
- {
- int r=random() % 62;
- r+=48;
- if (r>57) r+=7;
- if (r>90) r+=6;
- str[i++] = char(r);
- // so what if I work backwards?
- }
- return str;
-}
-
-
class DownloadProgressPackageReceiver : public callback::ReceiveReport<media::DownloadProgressReport>
{
callback::SendReport <DownloadResolvableReport> & _report;