1

I want to get the seed back which I set using set.seed(). Say if I set seed as set.seed(123), I want to get 123 back if I called some sort of function like get_seed().

I want to make sure that if the seed is set properly. Also, I want to see what's the value of seed when I set using Sys.time().

Barbara Gendron
  • 385
  • 1
  • 2
  • 16
D Surya Praveen
  • 321
  • 3
  • 17

1 Answers1

1

There is no function that is able to return the seed number that has been set at an earlier point in time.

The only way is to store the number somewhere before calling set.seed(). If you haven't done that, then there is no way to know which seed has been set.

TimTeaFan
  • 17,549
  • 4
  • 18
  • 39
  • 4
    If you have the output from immediately after you set the seed then [it can be brute forced](https://stackoverflow.com/questions/72756367/get-a-seed-to-generate-a-specific-set-of-pseudo-casual-number) - it won't be quick but if you're unlucky we're talking at most days rather than years. – SamR Mar 27 '23 at 11:53
  • 1
    @SamR: I have not thought about bruteforcing it, nice idea! However, it will only work if you have the output, and if `set.seed()` has been called directly before the function that generated the output. Further, this might work with small vectors, but if it is a computation-heavy operation, it might take much longer. – TimTeaFan Mar 27 '23 at 12:04
  • Yes absolutely - a last resort that might work in a desperate situation, depending on the circumstances. Definitely not a recommended workflow! – SamR Mar 27 '23 at 12:08