Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Random number generator giving same number

0 votes
asked Jun 7, 2019 by Aca99100 (120 points)
I am using srand(time(NULL)) in a while loop and i understand that it goes through the loop much faster than one second so it gives the same number in, lets say, 10 loops.

What bothers me is when i let it go for 1 million loops i see it print different numbers but when the process is complete there is only one same number in the output?

Does it fix the output to be the same number or am i seeing something else when the program is running.

1 Answer

0 votes
answered Aug 18, 2019 by anonymous
Not sure how to fix it yet, but an SRand will keep repeating the same numbers unless there is a time interval. Some kind of pause. Normally a Sleep(1000); would be enough, but it uses the <windows.h> library, which I don't think this code compiler allows.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.