I am new to Elixir / Erlang. I have been using Ruby for a while and I am wanting to convert this piece of code to Elixir / Erlang.
SecureRandom::random_bytes(16).each_byte.map { |b| sprintf("%02X",b) }.join
To have the same result, in Elixir you can use the Erlang module :crypto.strong_rand_bytes(16)
to generate the random number, and convert it using Base.encode16
Take a look at https://hexdocs.pm/elixir/Base.html to understand better the Base
module
.
Example:
:crypto.strong_rand_bytes(16) |> Base.encode16 # => "4B14868924ACEE98C9C9C404A1F87B08"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With