반응형
How to generate a random number in Elixir?
I need to generate a random number. I found the Enum.random/1
function, but it expects an enumerable such as a list or range of numbers.
Is that the only way to get a random number?
You can call Erlang's rand
module from Elixir code seamlessly.
random_number = :rand.uniform(n)
Will give a random number from 1 <= x <= n
&Enum.random/1
Enum.random(0..n)
will generate 0 to n
randomly
you can send list as argument too
ReferenceURL : https://stackoverflow.com/questions/38778054/how-to-generate-a-random-number-in-elixir
반응형
'programing' 카테고리의 다른 글
Output pyodbc cursor results as python dictionary (0) | 2021.01.17 |
---|---|
getting the value of an extra pivot table column laravel (0) | 2021.01.17 |
How can we set authorization for a whole area in ASP.NET MVC? (0) | 2021.01.17 |
jQuery - disable selected options (0) | 2021.01.17 |
InputStream vs InputStreamReader (0) | 2021.01.17 |