How to deal with large numbers from specific range?

84 views Asked by At

I have struggled with errors while modifying the below code to select numbers from specific range.

// RANDOM NUMBERS:
struct seed
{
    uint256_t seed;
    uint128_t counter;
};

/*
 * Create a new random seed.
 */
static struct seed *make_seed(void)
{
    struct seed *seed = (struct seed *)malloc(sizeof(struct seed));
    assert(seed != NULL);
    seed->counter = 0;
    if (!init_rand(seed, sizeof(struct seed)))
    {
        fprintf(stderr, "error: failed to init random seed\n");
        exit(EXIT_FAILURE);
    }
    if (seed->counter == 0)     // Sanity check...
    {
        fprintf(stderr, "error: random seed initialization failed\n");
        exit(EXIT_FAILURE);
    }
    return seed;
}

/*
 * Get a new random number.
 */
static uint256_t rand256(struct seed *seed)
{
    seed->counter++;
    return sha256(seed, sizeof(struct seed));
}

It's the code from pairgen.

How do I get the above function to select numbers from specific range?

I do not understand what seed is doing and how this outputs a number because sha256 requires data and size

0

There are 0 answers