[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] u8vector to numbers bignum
From: |
Kon Lovett |
Subject: |
Re: [Chicken-users] u8vector to numbers bignum |
Date: |
Thu, 28 May 2015 12:55:41 -0700 |
> On May 27, 2015, at 3:53 PM, chi <address@hidden> wrote:
>
> 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.
The integer result range extends to that of the limit parameter. Ex:
#;1> (use numbers srfi-27)
; loading /usr/local/lib/chicken/7/numbers.import.so ...
; loading /usr/local/lib/chicken/7/srfi-27.import.so ...
; loading /usr/local/lib/chicken/7/srfi-4.import.so …
...
; loading /usr/local/lib/chicken/7/srfi-4-checks.so ...
; loading /usr/local/lib/chicken/7/srfi-4-errors.so ..
#;2> (random-integer (expt 2 64))
15816285179193592418
#;3> (bignum? 15816285179193592418)
#t
> 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
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/chicken-users
- Re: [Chicken-users] u8vector to numbers bignum, (continued)
- Re: [Chicken-users] u8vector to numbers bignum, Peter Bex, 2015/05/28
- Re: [Chicken-users] u8vector to numbers bignum, cowan, 2015/05/28
- Re: [Chicken-users] u8vector to numbers bignum, Michele La Monaca, 2015/05/28
- Re: [Chicken-users] u8vector to numbers bignum, Peter Bex, 2015/05/28
- Re: [Chicken-users] u8vector to numbers bignum, Michele La Monaca, 2015/05/28
- Re: [Chicken-users] u8vector to numbers bignum, John Cowan, 2015/05/28
- Re: [Chicken-users] u8vector to numbers bignum, chi, 2015/05/28
- Re: [Chicken-users] u8vector to numbers bignum, cowan, 2015/05/29
- Re: [Chicken-users] u8vector to numbers bignum, Stephen Eilert, 2015/05/29
Re: [Chicken-users] u8vector to numbers bignum, Alex Shinn, 2015/05/28
Re: [Chicken-users] u8vector to numbers bignum,
Kon Lovett <=
Re: [Chicken-users] u8vector to numbers bignum, chi, 2015/05/28