git.fiddlerwoaroof.com
generator.h
7d075ab4
 /* Copyright (C) CJ Affiliate
  *
  * You may use, distribute and modify this code under  the
  * terms of the  GNU General Public License  version 2  or
  * later.
  *
  * You should have received a copy of the license with this
  * file. If not, you will find a copy in the "LICENSE" file
  * at https://github.com/cjdev/dual-control.
  */
 
55563eab
 #ifndef GENERATOR_H_
 #define GENERATOR_H_
 
 #include <string>
 #include <functional>
46cb80e7
 #include <sstream>
 #include <iomanip>
cff139be
 #include <cmath>
46cb80e7
 
 #include "sys_stdlib.h"
55563eab
 
 using generator = std::function<std::string()>;
 
23c0bd4d
 inline    std::string token_from_int (int x)
 {
     int v = std::abs (x % 1000000);
     std::ostringstream is;
     is << std::setfill ('0') << std::setw (6)<< v;
     return is.str();
 }
 
 inline generator make_generator (const stdlib &stdlib)
7d075ab4
 {
46cb80e7
     return [stdlib] {
23c0bd4d
         return token_from_int (stdlib.rand());
46cb80e7
     };
55563eab
 }
 
 #endif