Question about using BN_rand() I am working on a project and I'm noticing a peculiar behavior that I was hoping someone could tell me if it is correct or not.

I have a program that is trying to generate some random numbers using BN_rand().  Snippet of code follows:

BIGNUM *test = NULL;
unsigned char buffer[2048];
int fd = open("/dev/urandom", O_RDWR);
read(fd, buffer, 2048);
close(fd);

test = BN_new();
if (RAND_status() != 1)
    goto error3;

RAND_seed(buffer, 2048);

if (!BN_rand(test,2048,0,1))
    goto error3;

do_bn_print_name(stdout, "test", test);


Every time I run this program though, it gives me the same random number.  I was expecting the number to be changing after every run.  Am I doing this right or is this expected behavior?

Thanks for any assistance!
I couldn't reproduce the issue since you used some custom functions, but this works for me:

#include &lt;openssl/bn.h&gt;
#include &lt;openssl/rand.h&gt;
#include &lt;stdio.h&gt;

int main(void) {
    BIGNUM *test = NULL;
    unsigned char buffer[2048];
    FILE* fd = fopen("/dev/urandom", "r");
    fread(buffer, 1, 2048, fd);
    fclose(fd);

    test = BN_new();
    if (RAND_status() != 1)
        printf("Not enough entropy\n");

    RAND_seed(buffer, 2048);

    if (!BN_rand(test,2048,0,1))
        printf("Not enough entropy\n");

    printf("%s", BN_bn2dec(test));
    return 0;
}