lemon/random.h
changeset 551 49a39bae067c
parent 500 2b6d5d22bb23
child 576 33c6b6e755cd
equal deleted inserted replaced
25:3b85d4a9c027 26:f8342d367d02
   601     /// \brief Seeding from file or from process id and time
   601     /// \brief Seeding from file or from process id and time
   602     ///
   602     ///
   603     /// By default, this function calls the \c seedFromFile() member
   603     /// By default, this function calls the \c seedFromFile() member
   604     /// function with the <tt>/dev/urandom</tt> file. If it does not success,
   604     /// function with the <tt>/dev/urandom</tt> file. If it does not success,
   605     /// it uses the \c seedFromTime().
   605     /// it uses the \c seedFromTime().
   606     /// \return Currently always true.
   606     /// \return Currently always \c true.
   607     bool seed() {
   607     bool seed() {
   608 #ifndef WIN32
   608 #ifndef WIN32
   609       if (seedFromFile("/dev/urandom", 0)) return true;
   609       if (seedFromFile("/dev/urandom", 0)) return true;
   610 #endif
   610 #endif
   611       if (seedFromTime()) return true;
   611       if (seedFromTime()) return true;
   622     /// source of randomness, while the <tt>urandom</tt> does not
   622     /// source of randomness, while the <tt>urandom</tt> does not
   623     /// block the input, but it could give back bytes with worse
   623     /// block the input, but it could give back bytes with worse
   624     /// entropy).
   624     /// entropy).
   625     /// \param file The source file
   625     /// \param file The source file
   626     /// \param offset The offset, from the file read.
   626     /// \param offset The offset, from the file read.
   627     /// \return True when the seeding successes.
   627     /// \return \c true when the seeding successes.
   628 #ifndef WIN32
   628 #ifndef WIN32
   629     bool seedFromFile(const std::string& file = "/dev/urandom", int offset = 0)
   629     bool seedFromFile(const std::string& file = "/dev/urandom", int offset = 0)
   630 #else
   630 #else
   631     bool seedFromFile(const std::string& file = "", int offset = 0)
   631     bool seedFromFile(const std::string& file = "", int offset = 0)
   632 #endif
   632 #endif
   643     /// \brief Seding from process id and time
   643     /// \brief Seding from process id and time
   644     ///
   644     ///
   645     /// Seding from process id and time. This function uses the
   645     /// Seding from process id and time. This function uses the
   646     /// current process id and the current time for initialize the
   646     /// current process id and the current time for initialize the
   647     /// random sequence.
   647     /// random sequence.
   648     /// \return Currently always true.
   648     /// \return Currently always \c true.
   649     bool seedFromTime() {
   649     bool seedFromTime() {
   650 #ifndef WIN32
   650 #ifndef WIN32
   651       timeval tv;
   651       timeval tv;
   652       gettimeofday(&tv, 0);
   652       gettimeofday(&tv, 0);
   653       seed(getpid() + tv.tv_sec + tv.tv_usec);
   653       seed(getpid() + tv.tv_sec + tv.tv_usec);