0
What different between rand() and srand() functions in c++?
8 Respostas
+ 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
+ 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
+ 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
+ 2
https://www.sololearn.com/discuss/1030472/?ref=app
https://www.sololearn.com/discuss/122840/?ref=app
https://www.sololearn.com/discuss/960641/?ref=app
https://www.sololearn.com/discuss/247809/?ref=app
+ 1
thanks : )
+ 1
Seyedmm021 isn't srand(time(NULL)) more effective?
+ 1
Thanks Seyedmm021
+ 1
Thank