Question: I've seen quite a few recommendations for not seeding pseudo-random number generators more than once per execution, but never accompanied by a thorough explanation. Of course, it is easy to see why the following (C/C++) example is not a good idea:

```
int get_rand() {
  srand(time(NULL));
  return rand();
}

```

since calling `get_rand` several times per second produces repeated results. 

*But wouldn't the following example still be an acceptable solution?*

**MyRand.h**

```
#ifndef MY_RAND_H
#define MY_RAND_H

class MyRand
{
  public:
    MyRand();
    int get_rand() const;
  private:
    static unsigned int seed_base;
};

#endif

```

**MyRand.cpp**

```
#include <ctime>
#include <cstdlib>
#include "MyRand.h"

unsigned int MyRand::seed_base = static_cast<unsigned int>(time(NULL));

MyRand::MyRand()
{
  srand(seed_base++);
}

int MyRand::get_rand() const
{
  return rand();
}

```

**main.cpp**

```
#include <iostream>
#include "MyRand.h"

int main(int argc, char *argv[]) 
{
  for (int i = 0; i < 100; i++) 
  {
    MyRand r;
    std::cout << r.get_rand() << " ";
  }
}

```

i.e. even though `MyRand`:s constructor is called several times in rapid succession, each call to `srand` has a different parameter. Obviously, this is not thread-safe, but then again neither is `rand`.

Answer: 
Well it's extra processing that doesn't need to be done.

In that scenario I'd just call the constructor once with a time-based seed before the start of the loop. That will guarantee random results without the extra overhead of changing seeds for every iteration.

I wouldn't think your method is any *more* random than that.
You can think of random number generation (this is not strictly true implementation-wise any more, but serves as an illustration) as a table of values. If you remember doing any of this stuff in statistics for doing simple random samples, a seed basically tells you what row and column to start at in your big table of random numbers. Reseeding over and over again is simply unnecessary since we can already assume that the numbers are normally distributed already.

There is simply no added benefit to seeding more than once since this should be good enough (depending on the application). If you do need "more" random numbers, there are many methods of random number generation. One case that I can think of is to generate random numbers in a thread-safe manner.

While your solution is acceptable, your numbers will be no more random than seeding it once, globally. srand generally shouldn't belong in a constructor. If you'd like to support random numbers, seed once when the program starts, and forget about it.