Answers for "RANDOM INT C"

C++
6

c number randomizer

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
	int number, min, max;
	
	system("cls");
	printf("What is the minimum number?n");
	scanf("%d", &min);
	printf("What is the maximum number?n");
	scanf("%d", &max);
	
	printf("nThe numbers:n");
	srand(time(0));
	number = (rand() % (max - min + 1)) + min;
	printf("%d ", number);
	
	return 0;
}
Posted by: Guest on December-15-2020
6

how to genrate a random number in C

#include <time.h>
#include <stdlib.h>

srand(time(NULL));   // Initialization, should only be called once.
int r = rand();      // Returns a pseudo-random integer between 0 and RAND_MAX.
Posted by: Guest on June-18-2020
1

random number c

#include <stdio.h>
#include <time.h>

int main(){
   /*this is the seed that is created based on how much 
  time has passed since the start of unix time. 
  In this way the seed will always vary every time the program is opened*/
	srand(time(NULL));
  	int max;
  	int min;
  	int n;
  	printf("give me the minimum number?n");
   	scanf("%d", &min);
	printf("give me the maximum number?n");
	scanf("%d", &max);
  	//method to derive a random number
  	n = rand() % (max - min + 1) + min;
  	printf("random number:%d", n);
  	return 0;
}
Posted by: Guest on October-02-2021
1

c rand range

rand() % (max_number + 1 - minimum_number) + minimum_number
Posted by: Guest on February-10-2020

Browse Popular Code Answers by Language