srand(time(NULL)) Causing program to hang

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
post the code
closed account (j3Rz8vqX)
A quick search:

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.
yea but why doesn't it work when it's called more than once and why does it hang up the program when it's in a loop though?

the comments from the people in the link post above only says the same thing, which is "call it once, and don't use it in a loop"

but my question is why? why does looping cause it to hang?
Last edited on
Sounds like your code has an infinite loop. But unless you post the actual code, it's not possible to give any specific or detailed explanation.
Last edited on
Topic archived. No new replies allowed.