Efficient way of creating a vector of length L with unique elements

This is called “random sampling without replacement” and is implemented e.g. by StatsBase.sample.

See also Sampling from a list of integers without repetition and Sampling without replacement.

1 Like