BigInt icon indicating copy to clipboard operation
BigInt copied to clipboard

`big_random` function: mistake in description and better implementation suggestion

Open B1Z0N opened this issue 6 years ago • 3 comments

Error in description

I assume that author has written right implementation and forgot about description and not otherwise. So he meant to generate positive BigInts. Then this:

Returns a random BigInt with a specific number of digits

should be changed to

Returns a random positive BigInt with a specific number of digits

This should be fixed in include/functions/random.hpp and README.md.

Better implementation

  1. std::random_device is used to generate random digits, but it is not intended to be used that way for general purposes(read this). So I suggest to use the modern way - std::mt19937. Properly seeded it has 2^19937-1 potential states(that's a lot).

  2. When we are using % operation to achieve uniform integer distribution, that's not the right way, because some numbers are more likely to come up(read this for example). So let's use the right and modern way - std::uniform_int_distribution to generate

    • digits in BigInt number.
    • random length of BigInt number

B1Z0N avatar Aug 29 '19 10:08 B1Z0N

this looks nice, i would like to work on that

Prhmma avatar Oct 20 '19 14:10 Prhmma

let's start, add your suggestions or some code please

anyway, we can't do much without @faheel's attention here

B1Z0N avatar Oct 25 '19 11:10 B1Z0N

@B1Z0N Sorry for not taking a look at this for almost a year! Your idea seems good. I'll review your PR when I get more time.

And I really don't remember whether the initial intention was to only create positive BigInts or did I forget about negative numbers :smile:

faheel avatar Oct 05 '20 18:10 faheel