You shouldn’t call srand()
before each call to rand()
. Call it once – somewhere at the start of your program.
The problem is you restart the random generator so it starts to produce the very same pseudorandom sequence from the very same point.
More Related Contents:
- How can I use the output of a rand function, simulating 2 die rolls?
- Random generation of numbers? [closed]
- Generating random integer from a range
- Generate random numbers uniformly over an entire range
- Random float number generation
- Recommended way to initialize srand?
- Weighted random numbers
- Why do I get the same sequence for every run with std::random_device with mingw gcc4.8.1?
- Why is the use of rand() considered bad?
- How to succinctly, portably, and thoroughly seed the mt19937 PRNG?
- How do I create a random alpha-numeric string in C++?
- How do you generate a random double uniformly distributed between 0 and 1 from C++?
- How do I scale down numbers from rand()?
- Boost random number generator
- rand() generating the same number – even with srand(time(NULL)) in my main!
- Generating m distinct random numbers in the range [0..n-1]
- What’s the Right Way to use the rand() Function in C++?
- How to generate random variable names in C++ using macros?
- What is the best way to generate random numbers in C++?
- Program is generating same random numbers on each run? [duplicate]
- Why is the new random library better than std::rand()?
- Does std::mt19937 require warmup?
- Vary range of uniform_int_distribution
- What is a good random number generator for a game?
- stl random distributions and portability
- Why Aren’t `std::uniform_int_distribution` and `std::uniform_int_distribution` Allowed?
- C++11 random numbers
- C++11 cross compiler/standard library random distribution reproducibility
- C++ uniform_int_distribution always returning min() on first invocation
- Generate N random numbers within a range with a constant sum