File: EasyRandom.hh

package info (click to toggle)
rdfind 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 648 kB
  • sloc: cpp: 1,670; sh: 1,622; makefile: 32
file content (35 lines) | stat: -rw-r--r-- 798 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
   copyright 2018 Paul Dreik
   Distributed under GPL v 2.0 or later, at your option.
   See LICENSE for further details.
*/
#ifndef RDFIND_EASYRANDOM_HH_
#define RDFIND_EASYRANDOM_HH_

#include <string>

/**
 * Helper object to "provide a replacement of std::rand()"
 * It is automatically seeded.
 * The state is global, and not held in the class
 * This class is not thread safe.
 */
class EasyRandom
{
public:
  class GlobalRandom;
  EasyRandom();
  /**
   * makes N random characters, suitable to use for a random filename.
   * @param N
   * @return
   */
  std::string makeRandomFileString(std::size_t N = 16);

private:
  // keep a reference to the global magic static, to avoid the cost of thread
  // safe initialization.
  GlobalRandom& m_rand;
};

#endif /* RDFIND_EASYRANDOM_HH_ */