Trying to write a simple sampling function

If you want to create strings rather than vectors of string/char, you may want to use randstring from the Random stdlib. Normally, it’s also cleaner to represent characters as Chars, rather than as unit-length Strings:

using Random: randstring
alphabet = ['i', 'a', 'p', 't']   # single quotes

jl> randstring(alphabet, 7)
"pttiitp"

(If your alphabet is short, you could even use a tuple, alphabet = ('i', 'a', 'p', 't'), for extra performance :wink: )

4 Likes