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 : how to genrate a random number 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 : 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