]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/random/example/password.cpp
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
12 For the source of this example see
13 [@boost://libs/random/example/password.cpp password.cpp].
15 This example demonstrates generating a random 8 character
20 #include <boost/random/random_device.hpp>
21 #include <boost/random/uniform_int_distribution.hpp>
25 /*<< We first define the characters that we're going
26 to allow. This is pretty much just the characters
27 on a standard keyboard.
30 "abcdefghijklmnopqrstuvwxyz"
31 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34 "`~-_=+[{]}\\|;:'\",<.>/? ");
35 /*<< We use __random_device as a source of entropy, since we want
36 passwords that are not predictable.
38 boost::random::random_device rng
;
39 /*<< Finally we select 8 random characters from the
40 string and print them to cout.
42 boost::random::uniform_int_distribution
<> index_dist(0, chars
.size() - 1);
43 for(int i
= 0; i
< 8; ++i
) {
44 std::cout
<< chars
[index_dist(rng
)];
46 std::cout
<< std::endl
;