What different between rand() and srand() functions in c++? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

What different between rand() and srand() functions in c++?

13th Jul 2018, 5:42 PM
Rytis Karalius
Rytis Karalius - avatar
8 Réponses
+ 4
every time you run the app without srand you will see same number but with srand it won’t be same (Note:It’s better use srand(time(0))[you have to import time.h] for getting better resualt
13th Jul 2018, 7:17 PM
Seyedmm021
Seyedmm021 - avatar
+ 4
hinanawi I believe the end result of time(0) and time(NULL) is the same. tried this today. https://code.sololearn.com/c5QQ2THv04VG/?ref=app
14th Jul 2018, 5:01 PM
Manual
Manual - avatar
+ 3
Rytis Karalius The rand() returns a random number. srand() seeds the random function. Typicaly used to make the function give more random values. https://www.sololearn.com/learn/CPlusPlus/1638/?ref=app
13th Jul 2018, 6:01 PM
Manual
Manual - avatar
+ 1
thanks : )
13th Jul 2018, 6:38 PM
Rytis Karalius
Rytis Karalius - avatar
+ 1
Seyedmm021 isn't srand(time(NULL)) more effective?
13th Jul 2018, 10:11 PM
hinanawi
hinanawi - avatar
+ 1
Thanks Seyedmm021
14th Jul 2018, 1:17 PM
Rytis Karalius
Rytis Karalius - avatar
+ 1
Thank
14th Jul 2018, 5:40 PM
Rytis Karalius
Rytis Karalius - avatar