Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rand(BigInt) #24907

Closed
oxinabox opened this issue Dec 4, 2017 · 5 comments
Closed

rand(BigInt) #24907

oxinabox opened this issue Dec 4, 2017 · 5 comments
Labels
bignums BigInt and BigFloat randomness Random number generation and the Random stdlib

Comments

@oxinabox
Copy link
Contributor

oxinabox commented Dec 4, 2017

GMP and MPFR have random number generator functions.

However, they are not currently exposed to julia.

It seems like they should be, as generating random numbers correctly is hard.
Making sure srand works properly may take some doing.

(from https://stackoverflow.com/questions/47628275/random-bigfloats-julia)

Update: I see now rand(BigFloat) works on master, but not rand(BigInt)

@rfourquet
Copy link
Member

Do you request specifically the random generation provided by those libraries? If so, see #13950 for BigFloat, I would be willing to contribute finishing this work. For GMP, a similar work would be quite easy. But it's unlikely that those belong to Base, in particular as the functionality is already implemented in pure Julia (for BigFloat I guess it's only on 0.7).

@rfourquet rfourquet added the randomness Random number generation and the Random stdlib label Dec 4, 2017
@oxinabox
Copy link
Contributor Author

oxinabox commented Dec 4, 2017

No, not using those libraries I was just observing they exist.
Implementing directly in julia seems completely reasonable.

I see that rand(BigFloat) does work on master.
I only checked rand(BigInt) and I just assumed rand(BigFloat) was not working either. My bad.

@oxinabox oxinabox changed the title rand(BigInt) and rand(BigFloat) rand(BigInt) Dec 4, 2017
@rfourquet
Copy link
Member

rfourquet commented Dec 4, 2017

And rand(BigInt) can't exist (if you want a uniform distribution) because this type is unbounded. One the other hand, what has been available for a while is rand(::UnitRange{BigInt}). So I will close.

@oxinabox
Copy link
Contributor Author

oxinabox commented Dec 4, 2017

Oh of-course it can't.
I really didn't think this one through. :-S
I was thinking since rand(Int) works rand(BigInt) should too.
But you are right. It can't.

@rfourquet rfourquet added the bignums BigInt and BigFloat label Dec 4, 2017
@StefanKarpinski
Copy link
Member

StefanKarpinski commented Dec 4, 2017

It could check how much memory you have and generate a random integer between ±2^((size of RAM) >> 1). But I suspect that might not be the most popular method definition ever :trollface:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bignums BigInt and BigFloat randomness Random number generation and the Random stdlib
Projects
None yet
Development

No branches or pull requests

3 participants