static int test_rand()
{
    BIGNUM *bn = BN_new();
    int st = 0;

    if (bn == NULL)
        return 0;

    /*
     * Test BN_rand for degenerate cases with |top| and |bottom| parameters.
     */
    if (BN_rand(bn, 0, 0 /* top */ , 0 /* bottom */ )) {
        fprintf(stderr, "BN_rand1 gave a bad result.\n");
        goto err;
    }
    if (BN_rand(bn, 0, 1 /* top */ , 1 /* bottom */ )) {
        fprintf(stderr, "BN_rand2 gave a bad result.\n");
        goto err;
    }

    if (!BN_rand(bn, 1, 0 /* top */ , 0 /* bottom */ ) || !BN_is_word(bn, 1)) {
        fprintf(stderr, "BN_rand3 gave a bad result.\n");
        goto err;
    }
    if (BN_rand(bn, 1, 1 /* top */ , 0 /* bottom */ )) {
        fprintf(stderr, "BN_rand4 gave a bad result.\n");
        goto err;
    }
    if (!BN_rand(bn, 1, -1 /* top */ , 1 /* bottom */ ) || !BN_is_word(bn, 1)) {
        fprintf(stderr, "BN_rand5 gave a bad result.\n");
        goto err;
    }

    if (!BN_rand(bn, 2, 1 /* top */ , 0 /* bottom */ ) || !BN_is_word(bn, 3)) {
        fprintf(stderr, "BN_rand6 gave a bad result.\n");
        goto err;
    }

    st = 1;
err:
    BN_free(bn);
    return st;
}