+ 1
When can we use the rand() function and how ?!
4 Respostas
+ 11
@Zeke Williams
well explaination.
+ 6
to generate random number of cause ......😶
+ 4
First, make sure you include a couple of things:
#include <cstdlib> // this is for rand() and srand()
#include <ctime> // this is for time()
Then, in main you will need to set the seed for the rand function before calling rand();
int main() {
srand(time(NULL));
int rand0to9 = rand() % 10; // here I've called it to give me a random int 0 to 9
return 0;
}
0
thnx @zeke_williams