How to create a random binary array with b bits?

julia> using Random: bitrand

julia> bitrand(10)
10-element BitArray{1}:
 0
 0
 0
 1
 0
 0
 1
 1
 0
 0

Performance of bitrand is quite good:

julia> b = 10^6;

julia> @btime BitArray(rand(Bool, $b));
  1.623 ms (5 allocations: 1.07 MiB)

julia> @btime bitrand($b);
  20.637 μs (3 allocations: 122.23 KiB)
11 Likes