## either load the saved random seed and state data from the ## serialization (resume a paused compuatation), or start with ## new state data and the given random seed (start new ## compuation) my ($foo, $bar, $random_seed) = deserialize('saved') || initial_values(); while (1) { srand($random_seed); ## some crunching on $foo, $bar, using lots of rand() ## decide what the next iteration's seed will be $random_seed = int rand( 2 << 31 ); if (check_for_user_interrupt()) { ## save state, along with the seed for next iteration serialize('saved', $foo, $bar, $random_seed); exit; } }