this is ridiculous rand() operator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

this is ridiculous rand() operator

this code always shows just these numbers: 41 18467 6334 26500 19169 15724 11478 29358 26962 24464 i thought that this code shows really random numbers. https://code.sololearn.com/cff0MFWq908q/#cpp

8th Mar 2018, 9:51 AM
Alireza1996Sh
Alireza1996Sh - avatar
2 Answers
+ 4
To get truly random numbers you have to give a random seed Use: #include <ctime> then srand(time(0)); That uses the current time(which constantly changes) as the seed making the generator more random
8th Mar 2018, 9:54 AM
David Akhihiero
David Akhihiero - avatar
+ 1
thanks for ur answer dear Yerucham https://code.sololearn.com/clBV7RSf30Bd/#cpp
8th Mar 2018, 10:03 AM
Alireza1996Sh
Alireza1996Sh - avatar