bitrand

bitrand([rng], [dims...])

Generate a BitArray of random boolean values.

Examples

  1. Generate a random boolean vector:

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

    This example generates a random boolean vector of length 5.

  2. Generate a random boolean matrix:

    julia> bitrand(2, 3)
    2×3 BitArray{2}:
    1  0  0
    1  1  1

    It produces a 2x3 random boolean matrix.

  3. Generate a random boolean array using a specific random number generator:
    julia> rng = MersenneTwister(1234);
    julia> bitrand(rng, 4)
    4-element BitArray{1}:
    1
    1
    0
    0

    In this example, the MersenneTwister random number generator is used to generate a random boolean vector of length 4.

Common mistake example:

julia> bitrand(-1)
ERROR: ArgumentError: Invalid dimension '-1': must be a non-negative integer or a tuple of non-negative integers

In this example, a negative value is provided as the dimension. The dimension argument should be a non-negative integer or a tuple of non-negative integers. Make sure to provide valid dimensions when using the bitrand function.

See Also

bitrand, MersenneTwister, rand, randcycle, randexp, randexp!, randjump, randn, randn!, RandomDevice, randperm, randsubseq, randsubseq!, shuffle, srand,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: