GF2::Vector — Create with a Random Fill

Factory method to construct a bit-vector whose elements are determined by independent random draws from a Bernoulli distribution:

static Vector random(std::size_t n, double prob_one = 0.5); (1)
1 Returns a bit-vector of size n.

The probability that an element in the bit-vector is 1 is prob_one. The default, 0.5 means the element values will be determined by tossing a fair coin a total of n times. At the extremes, if this parameter is 1.0 then the elements will all be 1, if it is 0.0 then the elements will all be 0.

Throws a std::invalid_argument exception if the prob_one parameter is not in the valid range \(\[0, 1]\).
Example
#include <GF2/GF2.h>
int main()
{
    auto v = GF2::Vector<>::random(16);
    std::cout << v << std::endl;
}
Output
1011010011010001