random in c++
#include <iostream> #include <stdlib.h> #include <time.h> using namespace std; int main() { int num; srand(time(0)); num = rand() % 10 + 1; cout << num << endl; }
c++ random
#include <cstdlib> #include <iostream> #include <ctime> int main() { std::srand(std::time(nullptr)); // use current time as seed for random generator int random_variable = std::rand(); std::cout << "Random value on [0 " << RAND_MAX << "]: " << random_variable << '\n'; }
Source: en.cppreference.com
how to make a random number in c++
#include <iostream> #include <stdlib.h> #include <time.h> using namespace std; int main() { srand(time(NULL) ); const char arrayNum[7] = {'0', '1', '2', '3', '4', '5', '6'}; int RandIndex = rand() % 7; cout<<RandIndex<<endl; return 0; }
c++ random number
#include<stdlib.h> #include<ctime> using namespace std; //Generate random numbers int main(){ srand(time(0)); for (int i = 0; i < 10; i++){ cout<< (rand() % 10) + 1<<" ";