示例#1
0
static void test_basic_set(Generator *gen) {
        uint32_t i, j, n;
        char c, *s;

        printf("Test standard set of 8k variants..\n");

        for (i = 0; i < 8192; ++i) {
                generator_seed_u32(gen, i);
                generator_reset(gen);

                j = 0;
                n = 0;
                s = NULL;

                do {
                        c = generator_step(gen);
                        if (j >= n) {
                                n = n ? (n * 2) : 128;
                                s = realloc(s, n);
                                assert(s);
                        }
                        s[j++] = c;
                } while (c);

                printf("  %u: %s\n", i, s);
                test_type(s);
                free(s);
        }
}
示例#2
0
/**
 * generator_seed_str() - seed generator
 * @gen:        generator to seed
 * @str:        string representation of the seed
 * @base:       base of the integer representation
 *
 * This seeds the given generator with the integer given in @str. The integer
 * must be given as ASCII string with a representation of base @base. Arbitrary
 * precision is supported.
 *
 * If there is currently a sequence ongoing, this has *no* effect on it. It
 * will only take effect on the *next* sequence you start.
 *
 * If @str is not formatted as an integer in base @base, this function will use
 * its first byte as binary seed. An error code is still returned!
 *
 * Return: 0 on success, negative error code if @str is wrongly formatted.
 */
int generator_seed_str(Generator *gen, const char *str, int base) {
        int r;

        r = mpz_set_str(gen->seed, str, base);
        if (r < 0) {
                generator_seed_u32(gen, *str);
                return -EINVAL;
        }

        return 0;
}