• Elixir: Super easy way to create random alphanumeric ids

With Nomad Rental we had a simple task; we want to create a random alphanumeric ID of six characters (e.g. QJ21KK). Elixir is a wonderful language that makes this incredibly easy to understand in code form:

def gen_reference() do
  min = String.to_integer("100000", 36)
  max = String.to_integer("ZZZZZZ", 36)

  |> Kernel.-(min)
  |> :rand.uniform()
  |> Kernel.+(min)
  |> Integer.to_string(36)

We define the lower and upper bounds in alphanumeric, convert them to integers and find a random number in between them. We then turn the random integer back to alphanumeric and voila!

The Author

Dan Schultzer is an active experienced entrepreneur, starting the Being Proactive groups, Dream Conception organization, among other things. You can find him at twitter

Like this post? More from Dan Schultzer

Comments? We would love to hear from you, write us at @dreamconception.