lemire / fastrand

Fast random number generation in an interval in Python: Up to 10x faster than random.randint.
Apache License 2.0
88 stars 12 forks source link

Should the result of pcg32() be signed? #14

Closed jnrbsn closed 3 years ago

jnrbsn commented 3 years ago

The C function pcg32_random() returns an unsigned uint32_t, but the pcg32() function exposed to Python calls Py_BuildValue() with "i", which causes it to return a signed int (docs). Is this a bug or was it intentional? I don't see this explicitly mentioned anywhere, but I assumed it would give me unsigned 32-bit integers, and I was surprised to see it giving me negative numbers.

lemire commented 3 years ago

You are correct, it should not be.

lemire commented 3 years ago

Fixed in a commit.

jnrbsn commented 3 years ago

It looks like you published a new version to PyPI (1.3.0), but the only available downloads are for Windows. So it won't let me install it on macOS or Linux. Previous versions had a source distribution available that would get used on macOS and Linux.

lemire commented 3 years ago

Right. Should be good now. Please check.

(It used to be automatic but travis is botching it.)

jnrbsn commented 3 years ago

I can install it now, and I can confirm it's no longer giving me negative integers. Thanks.

lemire commented 3 years ago

Thanks for the feedback. Hopefully this will prove useful.