There are two ways to do this; keep all of the individual data sets, or be able to re-generate each and every data set whenever we want.
Whether we are using a strategy of generating all of the data, or of sampling from a large dataset, or re-sampling (for a jackknife- or bootstrap-based study), we will need to generate a series of (pseudo-) random numbers. All of the pseudo-random number generators make use of a seed. We input some value, and then a series of numbers is generated. Once the seed is provided, the series is completely determined. Most implementations provide two possibilities for the seed:
- explicitly provide a seed value
- implicitly have the seed generated for us
Most generators make it simpler to one or the other of these, but pretty much every generator I have used allows both options. A common strategy for implicit seeding is to use the system's clock.
The key to being able to replicate runs is to capture the seed for every run. We can do this by using an implicit seed, and recording that seed (say by appending it to a file). I have found this approach to be extremely error prone, and don't advise it. Instead, my approach is to generate a seed file by using a random number generator (often with an implicit seed) to generate a file containing a large number of seed values., one for each replication. Then I copy the seed file to a backup (a separate disk or flash drive). In general, I will have one seed file per condition of the study. That file should contain at least the number of iterations I want. In general, I have some overage (at least 10% if I'm optimistic, 100% if I'm feeling pessimistic). That way if a specific run hiccups, my simulations can continue without running out of seeds.
Say that I call the file something clever, like "seed.dat". Each replication:
- creates a backup copy of the file--"seed.bak",
- reads the N values in the seed file,
- removes the top value, and
- writes N-1 values (without the top value) back to same file (seed.dat) for the next replication's use.
The purpose of the backup is to be able to kill the current run. I often want to pause the simulation to do some interim data analyses. Using this strategy, I can copy seed.bak to seed.dat, and resume the simulation.
This approach gives me two advantages:
- I can don't have to keep the individual data sets around, reducing the possibility that I'l run into storage problems
- I can re-generate any specific data set by simply using the corresponding seed value
- Finally, when I go to archive the files associated with the study, I only have to save the seed files, secure in the knowledge that I can recreate anything (from a single run to the entire study) at a moment's notice.