GF2::Matrix — Construct with a Random Fill

Class methods to construct a bit-matrix whose elements are determined by independent random draws from a Bernoulli distribution.

static Matrix random(std::size_t r, std::size_t c, double prob_one);    //  (1)
static Matrix random(std::size_t r, std::size_t c);                     //  (2)
static Matrix random(std::size_t n);                                    //  (3)
1 Returns an r x c sized bit-matrix where the probability that an element in the bit-matrix is 1 is prob_one.
2 Returns an r x c sized bit-matrix where the probability that an element in the bit-matrix is 1 is 0.5.
3 Returns an n x n square bit-matrix where the probability that an element in the bit-matrix is 1 is 0.5.

prob_one is the probability that an element in the bit-matrix is 1. The default, 0.5 means the element values will be determined by tossing a fair coin a total of r x c times (or n2 times in the square case). 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 m1 = GF2::Matrix<>::random(8);
    std::cout << m1 << std::endl;
}
Output
01000101
00000010
01111001
10000000
00100110
11101010
10101001
10010101