randsubseq!

randsubseq!(S, A, p)

Like randsubseq, but the results are stored in S (which is resized as needed).

Examples

  1. Generate a random subsequence of an array:

    julia> arr = [1, 2, 3, 4, 5];
    julia> subseq = Int[];
    julia> randsubseq!(subseq, arr, 0.5)
    2-element Array{Int64,1}:
    1
    4

    This example generates a random subsequence of the array arr with a probability of 0.5 for each element. The resulting subsequence is stored in the subseq array.

  2. Generate a random subsequence of a string:

    julia> str = "Julia Programming";
    julia> subseq = String[];
    julia> randsubseq!(subseq, str, 0.3)
    6-element Array{String,1}:
    "i"
    "a"
    "P"
    "g"
    "m"
    "g"

    It generates a random subsequence of the string str with a probability of 0.3 for each character. The resulting subsequence is stored in the subseq array of strings.

  3. Generate a random subsequence of a range:
    julia> rng = 1:10;
    julia> subseq = Int[];
    julia> randsubseq!(subseq, rng, 0.7)
    7-element Array{Int64,1}:
    1
    2
    4
    6
    7
    8
    9

    It generates a random subsequence of the range rng with a probability of 0.7 for each element. The resulting subsequence is stored in the subseq array.

Common mistake example:

julia> arr = [1, 2, 3, 4, 5];
julia> subseq = Int[];
julia> randsubseq!(subseq, arr, 1.5)
ERROR: ArgumentError: probability must be in the range [0, 1]

In this example, the probability provided is outside the valid range of [0, 1]. The probability argument must be a valid probability value between 0 and 1. Be sure to provide a valid probability value when using randsubseq!.

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: