Add functions that generate a random BigInt
The following functions that generate a random BigInt need to be implemented under include/functions/random.hpp:
-
[x] Having specific number of digits:
friend BigInt big_random(size_t num_digits);Returns a random
BigInthaving 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
BigIntsuch thatlow <= BigInt <= high.
Note: type T can be a BigInt, std::string or long long.
on which file I have to work to solve this issue?
Give me the file name.
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.
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);
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?
@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.
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.
@FR4NKESTI3N Sure, you can give it a try.
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.

@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.
Is this task still an open issue? If so, I would like to contribute.