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

Add functions that generate a random BigInt #19

Open
1 of 2 tasks
faheel opened this issue Jan 18, 2018 · 10 comments
Open
1 of 2 tasks

Add functions that generate a random BigInt #19

faheel opened this issue Jan 18, 2018 · 10 comments
Labels
enhancement New feature or request functions: random Random functions help wanted Extra attention is needed
Milestone

Comments

@faheel
Copy link
Owner

faheel commented Jan 18, 2018

The following functions that generate a random BigInt need to be implemented under include/functions/random.hpp:

  • Having specific number of digits:

    friend BigInt big_random(size_t num_digits);

    Returns a random BigInt having the specified number of digits. If the number of digits are not specified, use a random value for it.

  • Within a certain range:

    friend BigInt big_random(const T& low, const T& high);

    Returns a random BigInt such that low <= BigInt <= high.

Note: type T can be a BigInt, std::string or long long.

@faheel faheel added enhancement New feature or request help wanted Extra attention is needed labels Jan 18, 2018
@faheel faheel added this to the v1.0 milestone Jan 18, 2018
@faheel faheel mentioned this issue Jan 18, 2018
5 tasks
@faheel faheel added the functions: random Random functions label Jan 18, 2018
@asas2016SEC
Copy link

asas2016SEC commented Jan 18, 2018

on which file I have to work to solve this issue?

Give me the file name.

@faheel
Copy link
Owner Author

faheel commented Jan 18, 2018

The file include/functions/random.hpp doesn't exist yet, you'll have to create it. The "template" would be similar to that of math.hpp (in include/functions/), so you can duplicate and modify math.hpp.

@faheel
Copy link
Owner Author

faheel commented Jan 18, 2018

For reference, the following is the most appropriate way to generate true random numbers C++:

std::random_device rand_generator;
size_t rand_int = rand_generator();   // get a random number between 0 and UINT_MAX

Using this, one way to generate a random BigInt would be to keep appending randomly generated integers to BigInt.value:

rand_big.value += std::to_string(rand_int);

@IbrarYunus
Copy link

Hi, is this issue resolved yet?
As I wish to start contributing to open source projects (this is my first time doing opensource, so I may ask questions alot), and this seems a good point to start.
I will be using an editor in Windows 10 x64 to write code for this, is this okay?

@faheel
Copy link
Owner Author

faheel commented Feb 2, 2018

@IbrarYunus I've been working on the second function and it's almost done.

You can take up #18 if you're interested in contributing.

faheel referenced this issue Feb 2, 2018
that generates a random BigInt with a specific number of digits
@FR4NKESTI3N
Copy link

Can I do the function to generate a random number within some range? Have never contributed to any project so i thought some simple function would be good start.

@faheel
Copy link
Owner Author

faheel commented Jun 10, 2018

@FR4NKESTI3N Sure, you can give it a try.

@FR4NKESTI3N
Copy link

Sorry, I was unable to work past 2 weeks. I have studied the results of existing big_random() on octave and they appear to be uniformly distributed. Wouldn't it be better to use this existing function with modulo? Something like:

result = low + big_random(x)%(high - low);

where x can be adjuted to reduce calculations.

There dosen't seem to be a need to write an entirely new function unless normal distribution is required.

Some nice graphics I got in octave

stkaufer added a commit to stkaufer/BigInt that referenced this issue Oct 5, 2018
Random functions for long long, BigInt, and std::string using specialized Template functions.
@stkaufer
Copy link

stkaufer commented Oct 5, 2018

@faheel Check out branch GH-19-Random. Let me know if this meets the requirements for this issue and I'll create the Pull Request.

@alihaider1264
Copy link

alihaider1264 commented Oct 21, 2021

Is this task still an open issue? If so, I would like to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request functions: random Random functions help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants