+ 2
How do I make a random number in c++
9 Answers
+ 15
#include <iostream>
#include <cstdlib> // for rand(), srand()
#include <ctime> // for time()
int main()
{
srand(time(0));
// seed built-in RNG with current time
std::cout << 1+ rand() % 10;
// output random number between 1 to 10
return 0;
}
+ 8
Edited original answer. Please refer. đ
+ 7
keep going with the course. this is covered.
+ 7
@waylon Then post your criteria here lol.
+ 2
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand((int)time(0));
int i = 0;
while(i++ < 10) {
int r = (rand() % 100) + 1;
cout << r << " ";
}
return 0;
}
+ 2
thanks @Hatsy Rei but is there a was to make it with in certain criteria
+ 1
1-10 @Hatsy Rei
+ 1
Ok thanks @Hatsy Rei
0
To make a random number use the function "rand()" which is in cstdlib