StreamData: how to generate a list of 2 strings with varied length

Hi!, how do i generate a list contains only 2 strings with varied length ie [“foo”, “baaar”]?

I tried:

# returns ["QrGgkWA7o1", "NbWbClnTYk"]
Enum.take(StreamData.string(:alphanumeric, length: 10), 2)

You have defined that given strings need to have length: 10, so how you expect them to have different length?

hi @hauleth, yeah forgot to remove that length:10. But if i try this in iex session:

Enum.take(StreamData.string(:alphanumeric), 2)

it only returns something like ["l", "ku"] (list of empty strings, list of strings with length of 1 or 2) couple of times unless i specify like length: 10 option in StreamData.string

yeah @soyjeansoy it starts with the smallest strings and progresses into bigger lengths, not sure how “random” that can be.

iex(1)> StreamData.string(:alphanumeric) |> Enum.take(2)
["D", "k"]
iex(2)> StreamData.string(:alphanumeric) |> Enum.take(2)
["E", "yj"]
iex(3)> StreamData.string(:alphanumeric) |> Enum.take(20)
["j", "g", "yLc", "", "DxC8", "", "n", "q9kgIX", "", "Jg", "b", "jJs1",
 "3UrpsF", "IcNUZBQ", "NC70Mt6Y4Daa", "s61D8798DT", "KiBfNzUonUT0Bg", "DVWUXgE",
 "5J3s6GlISUrIGE", "SQLtS0KHTakmLhU"]
iex(4)> StreamData.string(:alphanumeric, max_length: 12) |> Enum.take(83)
["b", "LE", "", "", "H", "kMYa", "", "4hZuN", "jJ3dy", "0mGT9", "FURUUin",
 "DzOI", "TTZhhaw6N9", "82vV", "nOYc1QH7", "4BWy", "OLeM4nH53Qw", "TDgXLM",
 "tRl4ldXT", "vtu3H", "ZgRk", "", "o9xU", "S7wMlwblNv", "l3O0elqjVs1I",
 "y2uedOct", "8esTi7", "dntRYmip", "ZADJRjfc4X", "AW", "Skpd8cO5YzI", "",
 "OUxE", "QhFmCxkid", "", "XwofgD7aPVZ", "881", "xSgP5fmwnHbX", "Q6pF7jcLdx",
 "L53yvQVqgcDQ", "H", "FMci4VTvM", "BsVp", "56", "eA2ZV", "", "llEjsPyurF",
 "QFYnr", "uNIp", "kmbMS", ...]

You can pass a min_length if you don’t want them too small.

2 Likes

@rodrigues hanks for helping me out! i didnt know it starts to smallest (ill keep that in mind). sorry very late reply :frowning: