Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,900 questions

51,831 answers

573 users

How to generate 8 digit random number in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
  
#define N 20
  
int main(void)
{
    srand((unsigned)time(NULL));
	
	long x = 1000000;
	long y = 99999999;

	for (int i = 0; i < N; i++) 
		printf("%ld\n", rand() % (y - x + 1) + x);
     
    return 0;
}

 
 
/*
run:
 
1022328
1032689
1017893
1018076
1021484
1008525
1011816
1027084
1003252
1027955
1020480
1015082
1008105
1008871
1024815
1032640
1018943
1008347
1016492
1025656

*/

 



answered Apr 26, 2016 by avibootz

Related questions

1 answer 229 views
1 answer 157 views
1 answer 180 views
1 answer 352 views
1 answer 183 views
1 answer 678 views
...