Save and restore random state