soyjeansoy

soyjeansoy

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)

Marked As Solved

rodrigues

rodrigues

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.

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement