Skip to content

big_random function: mistake in description and better implementation suggestion #48

@B1Z0N

Description

@B1Z0N

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions