[erlang-questions] binary to bigint?

Jakob Cederlund <>
Wed Aug 8 11:33:24 CEST 2007


To make an erlang integer from crypto:rand_bytes:
 
big_random_int(Bytes) ->
    B = crypto:rand_bytes(Bytes),
    crypto:erlint(<<Bytes:32/unsigned-big-integer, B/binary>>).

I'd rather use rand_uniform/2, though.
/Jakob


Jakob Cederlund wrote:
> In crypto you also have rand_uniform/2 which accepts large integers, and 
> mpint/1 that converts from binary form.
>
> /Jakob
>
> Jim McCoy wrote:
>   
>> After bouncing through the various bits of doc related to io_lib I
>> can't quite seem to put together a quick function that will convert an
>> arbitrary binary to a big int (e.g. I want the integer for
>> crypto:rand_bytes(40)...)
>>
>> Any hints?
>>
>> jim
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>>   
>>     
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070808/6c5c4f6f/attachment.html>


More information about the erlang-questions mailing list