+ 1

Rand() in class

Can we put rand() function in a class if yes then can you please tell me how to do it

7th Nov 2021, 3:08 PM
Samaan Sayed
1 ответ
+ 2
Hope this helps.. .. https://www.sololearn.com/Discuss/976334/?ref=app you can use it wherever you need. a sample rand() use, by using class.. edit: Anjali kaur #include <iostream> using namespace std; class rands { public: void gen() { cout<<rand()%10;//generates random numbers between 0 to 9 } }; int main() { srand(time(0)); //setting seed rands r; //creation of object of class rands r.gen(); //calling function return 0; }
7th Nov 2021, 3:25 PM
Jayakrishna 🇮🇳