Generating big random numbers in C

I am not sure if I am writing into the correct section of this forum.

I want to generate big random numbers in C(not C++ please).By "big" I mean integers much bigger than srand(time(NULL)) and rand() functions' limit(32767).

I tried writing: (note:I am not able to see "code" tag button in this editor,so I am not using it)

1
2
3
4
5
6
7
//****

int randomnumber;
srand( time(NULL) );
randomnumber = (( rand() % 33 ) * ( rand() % 33 ) * ( rand() % 33) * ( rand() * 33) * (rand() % 33 )) + 1

//**** 


But I have doubts about it's randomness quality.Also there is another problem,the program can't know the maximum random number it should use before user input,so maximum random number may need to use much smaller maximum random number according to user input.

Is there a better algorithm to create big random numbers in C?
Last edited on
how big of a random number do you need?
the way i've seen it done before was
1
2
3
4
5
uint64_t random =
  (((uint64_t) rand() <<  0) & 0x000000000000FFFFull) ^ 
  (((uint64_t) rand() << 16) & 0x00000000FFFF0000ull) ^ 
  (((uint64_t) rand() << 32) & 0x0000FFFF00000000ull) ^
  (((uint64_t) rand() << 48) & 0xFFFF000000000000ull);
Last edited on
Thanks for your answer.(sorry for late reply)

how big of a random number do you need?


Up to 14 millions.

Last edited on
Topic archived. No new replies allowed.