Random int64 and float64 numbers

前端 未结 5 1153
失恋的感觉
失恋的感觉 2021-02-14 19:07

I\'m trying to generate random 64-bit integer values for integers and floats using Numpy, within the entire range of valid values for that type. To generate ran

相关标签:
5条回答
  • 2021-02-14 19:17

    For integers you could generate 2 32 bit random numbers and combine them:

    a + (b << 32)
    
    0 讨论(0)
  • 2021-02-14 19:18

    It would appear that the code for numpy.random.uniform() does high-low calculation at some point, and the Inf stems from there.

    Uniformly distributed integers are easy to generate as was shown. Uniformly distributed floating point numbers would require rather more careful thought.

    As for reporting these oddities as bugs, I think you should do either that or post a message to the project mailing list. That way you'll at least find out what the developers think is reasonable behaviour.

    0 讨论(0)
  • 2021-02-14 19:23

    I realize this is a very old question, but there is a new answer in Python 3.6.3:

    Python 3.6.3 |Anaconda, Inc.| (default, Oct  6 2017, 12:04:38) 
    [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import numpy as np
    >>> import sys
    >>> sys.maxsize
    9223372036854775807
    >>> np.random.randint(sys.maxsize)
    8550528944245072046
    
    0 讨论(0)
  • 2021-02-14 19:26

    The issue seems to be that the random_numbers method expects only 32-bit integers.

    According to ticket #555 random seeds can now be 64-bit as of version 1.1.0 I suggest downloading and installing the latest version of NumPy from here.

    0 讨论(0)
  • 2021-02-14 19:38

    I don't believe it refers to the random seed call. The simplest code I've got that falls into "Python int too large to convert to C long" is:

    x = numpy.random.random_integers(2**64,size=(SIZE,)).astype(numpy.uint64)
    

    numpy.version=1.5.0 here

    0 讨论(0)
提交回复
热议问题