How would I convert a u8vector to a bignum?

I'd like a good large random number, and there's srfi 27 for decent random
sources, and there's 'numbers' for bignum support, but srfi-27 only produces
fixnums or u8vectors. Logically I can't imagine a bignum isn't represented under
the hood by a block of bytes somehow, so it should be easy to turn a random byte
vector into a random bignum?

numbers itself only provides (random ...) which uses rand(3), and that's not
what I would call a good random number. Random sources don't really seem like
something a bignum library should worry about, anyway.

I could always do (number->string (u8vec_to_hex (random-u8vector #x20)) #x10)
but having a double sized hexadecimal intermediate isn't terribly appealing,
especially for a random number I might have to generate for hundreds of peers a
second in a high volume scenario. (Okay now I really /am/ being optimistic.)

Looking at the numbers source, it seems to be analagous to a vector whose first
element is a magic number indicating it's a bignum, and the rest of the vector
is the digits. I'm not qualified to say how hard that would be to turn a vector
into that, but it really doesn't seem like it would be too much trouble for
someone who was. Of course it would be seen as native endian, but since it's a
random number it doesn't matter too much.

_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to