So i wanted to write a program that generated almost real random numbers so i used the srand(time(NULL)). I put the srand(time(NULL)) inside a for loop along with Rand() function. Now my program hangs and nothing happens, cursor at my ubuntu terminal just blinks, nothing happens after i execute program, it does not go on next line of code.
now is this because srand(time(NULL)) is continously looping somehow? so it hangs my program? i have a base case for my for loop though, so it should have existed that loop. i'm not sure what's happening
Don't put srand any more than once in a program, and especially don't put it in a loop. It "seeds" the random number generator, which means it just sets the number that the generator works off.
After that, each time you call rand() effectively modifies the seed, providing another pseudo random number to be generated.
Basically, try to avoid calling srand more than once, Once will always be sufficient.