include/functions/random.hpp
BigInt big_random(size_t num_digits = 0) {
    std::random_device rand_generator;      // true random number generator

    if (num_digits == 0)    // the number of digits were not specified
        // use a random number for it:
        num_digits = 1 + rand_generator() % MAX_RANDOM_LENGTH;

    BigInt big_rand;
    big_rand.value = "";    // clear value to append digits

    // ensure that the first digit is non-zero
    big_rand.value += std::to_string(1 + rand_generator() % 9);

    while (big_rand.value.size() < num_digits)
        big_rand.value += std::to_string(rand_generator());
    if (big_rand.value.size() != num_digits)
        big_rand.value.erase(num_digits);   // erase extra digits

    return big_rand;
}
/*
    big_random (num_digits)
    -----------------------
    Returns a random BigInt with a specific number of digits.
*/
big_random (num_digits)
Returns a random BigInt with a specific number of digits.
big_random ( num_digits ) Returns a random BigInt with a specific number of digits .
BigInt big_random(size_t num_digits = 0) {
    std::random_device rand_generator;      
    if (num_digits == 0)    
        num_digits = 1 + rand_generator() % MAX_RANDOM_LENGTH;
    BigInt big_rand;
    big_rand.value = "";    
    big_rand.value += std::to_string(1 + rand_generator() % 9);
    while (big_rand.value.size() < num_digits)
        big_rand.value += std::to_string(rand_generator());
    if (big_rand.value.size() != num_digits)
        big_rand.value.erase(num_digits);   
    return big_rand;
}
BigInt big_random ( size_t num_digits = 0 ) { std :: random_device rand_generator ; if ( num_digits == 0 ) num_digits = 1 + rand_generator ( ) % MAX_RANDOM_LENGTH ; BigInt big_rand ; big_rand . value = " " ; big_rand . value += std :: to_string ( 1 + rand_generator ( ) % 9 ) ; while ( big_rand . value . size ( ) < num_digits ) big_rand . value += std :: to_string ( rand_generator ( ) ) ; if ( big_rand . value . size ( ) != num_digits ) big_rand . value . erase ( num_digits ) ; return big_rand ; }
big_random (num_digits)
Returns a random BigInt with a specific number of digits.
big_random ( num_digits ) Returns a random BigInt with a specific number of digits .
// true random number generator // the number of digits were not specified // use a random number for it: // clear value to append digits // ensure that the first digit is non-zero // erase extra digits