C Random

[Solved] C Random | Vb - Code Explorer | yomemimo.com
Question : random number in c

Answered by : samy-chaabi

#include <stdio.h>
#include <stdlib.h>
#include <time.h> #define randnum(min, max) \ ((rand() % (int)(((max) + 1) - (min))) + (min))
int main()
{ srand(time(NULL)); printf("%d\n", randnum(1, 70));
}

Source : https://stackoverflow.com/questions/822323/how-to-generate-a-random-int-in-c | Last Update : Sat, 10 Sep 22

Question : random number c

Answered by : davide-santoro

#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;
} 

Source : | Last Update : Sat, 09 Oct 21

Question : random in c

Answered by : hilarious-hare-iwi2ar8bhum0

#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.

Source : https://stackoverflow.com/questions/822323/how-to-generate-a-random-int-in-c | Last Update : Thu, 25 Jun 20

Question : random number c

Answered by : nutty-narwhal-36doso7eldz0

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{ int card; /* Do this only once at the start of your program, otherwise your sequence of numbers (game) will always be the same! */ srand(time(NULL)); /* Choose a number between 1 and 10 - we've called this 'card' because the number represents a card from ace to a ten in this program (rand() produces a large random int, we find the remainder from diving by 10 using '%' mod operator, then add 1 so the card can't be 0) */ card = rand() % 10 + 1; printf ("It's a %d.\n", card);
}

Source : https://modules.lancaster.ac.uk/pluginfile.php/3213957/mod_label/intro/scc110-problem-set-3.html?time=1666556374950 | Last Update : Tue, 01 Nov 22

Question : random number c

Answered by : lara-combina

//Note: Don't use rand() for security.
#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.

Source : https://stackoverflow.com/questions/822323/how-to-generate-a-random-int-in-c | Last Update : Tue, 30 Aug 22

Answers related to c random

Code Explorer Popular Question For Vb