How to generate a random number in Elixr?

In this article let’s discuss about Elixir random number. Let’s go through the following methods without any delay 🙂

Method 1:

$ Enum.random(0..n)
#will generate 0 to n randomly. you can send list as argument too.

Method 2 :

You can call Elixr’s rand module from Elixr code seamlessly.

$ random_number = :rand.uniform(n)

Will give a random number from 1<= x <=n

Hope the above methods works for you. Happy Learning and get back to us Anytime.

Realted Posts : Map merge elixir