When can we use the rand() function and how ?! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

When can we use the rand() function and how ?!

20th Mar 2017, 10:20 AM
azize bnd
azize bnd - avatar
4 Answers
+ 11
@Zeke Williams well explaination.
22nd Mar 2017, 1:16 AM
Agus Mei
Agus Mei - avatar
+ 6
to generate random number of cause ......😶
20th Mar 2017, 10:38 AM
Leon lit
Leon lit - avatar
+ 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; }
22nd Mar 2017, 12:37 AM
Zeke Williams
Zeke Williams - avatar
0
thnx @zeke_williams
22nd Mar 2017, 7:32 AM
azize bnd
azize bnd - avatar