[#basic_random_generator]
== <boost/uuid/{zwsp}basic_random_generator.hpp>

:idprefix: basic_random_generator_

=== Synopsis

[source,c++]
----
namespace boost {
namespace uuids {

template<class UniformRandomNumberGenerator>
class basic_random_generator
{
private:

    // exposition only
    UniformRandomNumberGenerator* p_;
    UniformRandomNumberGenerator g_;

public:

    using result_type = uuid;

    basic_random_generator();

    explicit basic_random_generator( UniformRandomNumberGenerator& gen );
    explicit basic_random_generator( UniformRandomNumberGenerator* pGen );

    result_type operator()();
};

}} // namespace boost::uuids
----

=== basic_random_generator

The class template `basic_random_generator` generates a version 4 random number-based UUID from a random number generator
(one that conforms to the standard concept https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerator[UniformRandomBitGenerator]
or to the Boost.Random concept https://www.boost.org/doc/libs/1_85_0/doc/html/boost_random/reference.html#boost_random.reference.concepts.uniform_random_number_generator[UniformRandomNumberGenerator]).

The default constructor will seed the random number generator with entropy obtained from `std::random_device`.

Additional constructors allow you to provide your own `UniformRandomNumberGenerator` and you are responsible for properly seeding it if necessary.

```
basic_random_generator();
```

Effects: :: Value-initializes `g_` and initializes `p_` to `nullptr`.
  If `g_.seed()` is a valid expression, calls `g_.seed( seed_seq );`
  to seed `g_`, where `seed_seq` is an object providing a
  `generate( first, last )` member function that fills the range
  `[first, last)` using entropy obtained from `std::random_device`.

NOTE: Random number generators conforming to the standard concept https://en.cppreference.com/w/cpp/named_req/RandomNumberEngine[RandomNumberEngine]
  or the Boost.Random concept https://www.boost.org/doc/libs/1_85_0/doc/html/boost_random/reference.html#boost_random.reference.concepts.pseudo_random_number_generator[PseudoRandomNumberGenerator]
  provide such `seed` member functions.

```
explicit basic_random_generator( UniformRandomNumberGenerator& gen );
```

Effects: :: Value-initializes `g_` and initializes `p_` to `&gen`.

```
explicit basic_random_generator( UniformRandomNumberGenerator* pGen );
```

Effects: :: Value-initializes `g_` and initializes `p_` to `pGen`.

```
result_type operator()();
```

Effects: :: Generates and returns a version 4 UUID using random numbers
  obtained from `*p_`, if `p_ != nullptr`, or from `g_`, otherwise.

Example: ::
+
```
using namespace boost::uuids;

basic_random_generator<boost::mt19937> bulkgen;

for( int i = 0; i < 1000; ++i )
{
    uuid u = bulkgen();
    // do something with u
}
```
