Why the following code produce different random numbers even thoug it has no seeding process? Shouldn`t the output be always 41? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why the following code produce different random numbers even thoug it has no seeding process? Shouldn`t the output be always 41?

for (x=0;x<10;x++) { cout << rand()<<endl; }

28th May 2017, 3:56 AM
Rui Borges
Rui Borges - avatar
2 Answers
+ 6
no. it will always produce the same 'set' of numbers. it is the same as if you had set a seed and are using the same number everytime
28th May 2017, 4:04 AM
jay
jay - avatar
+ 3
What jay said For a true random value look at this code https://code.sololearn.com/ce1uCi9fvZ7b/?ref=app
28th May 2017, 4:26 AM
DeleteThisAccount