Generate large numbers with srand () in c

I want to generate large random numbers in c. The problem is that the greatest amount of srand () can generate around 37000. I want to create a number in intervall of 70,000 to 2150000000. Can anyone help me with this.

Random number generator:

#include <stdio.h> #include <time.h> #include <stdlib.h> int main () { srand(time(NULL)); int i; for (i=0; i<50; i++) { int random = rand(); printf("%d\n",random); } return 0; } 
+5
source share
1 answer

First of all, mark RAND_MAX for the maximum value that can be generated using rand() .

You can put two rand() results into one value.

 int random = (rand() << 16) | rand(); 
+4
source

All Articles