-1

Is there any way to remove the seed value? I just ran a sample code as below

set.seed(912)
sample(10)

I got below result.

[1]  5  8  2 10  9  3  4  7  1  6

Now how do I stop the seed value. I closed my R session without saving and ran the same code as above after re-opening and got the result in same sequence.

I got below code from one of the questions related to seed but that also didn't work.

set.seed(Sys.time())
mockash
  • 1,204
  • 5
  • 14
  • 26
  • `?set` says something about `.Random.seed`, is that what you are looking for? – llrs Nov 03 '16 at 11:11
  • 1
    Try `set.seed(seed = NULL); sample(10)` ("If called with seed = NULL it re-initializes (see ‘Note’) as if no seed had yet been set.") – talat Nov 03 '16 at 11:12
  • @docendodiscimus I ran the same code `set.seed(seed = NULL)` and then `set.seed(912); sample(10)` but again I got the same sequence `[1] 5 8 2 10 9 3 4 7 1 6` – mockash Nov 03 '16 at 11:15
  • I am not sure, what do you mean by `remove`. Try this sequence of execution `set.seed(912); sample(10); sample(10)`. The first and second output are different. – Ronak Shah Nov 03 '16 at 11:23
  • @RonakShah I mean I want to reset the seed or I don't want any seed value to exist. After resetting the seed when i run the `set.seed(912); sample(10)` I want a new set of values. – mockash Nov 03 '16 at 11:29
  • Everytime you run `set.seed(912); sample(10)`, you'll get the same values. That is for what `seed` values are. You run it on any system on any environment. `set.seed(912); sample(10)` would give you the same values. For different results you need different `seed` value. `set.seed(913); sample(10)` . – Ronak Shah Nov 03 '16 at 11:32
  • @RonakShah You mean to say there is no way to reset or nullify the seed value that is already stored? – mockash Nov 03 '16 at 11:38
  • @Yash not that I am aware of. – Ronak Shah Nov 03 '16 at 11:41
  • 4
    Maybe `# set.seed(912)` ? – zx8754 Nov 03 '16 at 11:56

1 Answers1

17

Here is the script which comes from the help menu - i found it in this post: Questions about set.seed() in R

rm(.Random.seed, envir=globalenv())

Here's an example:

> set.seed(912)
> rm(.Random.seed, envir=globalenv())
> sample(10)
 [1]  1  8  2 10  3  4  6  7  9  5
> set.seed(912)
> rm(.Random.seed, envir=globalenv())
> sample(10)
 [1]  2  9  3  4 10  7  6  8  1  5
> set.seed(912)
> rm(.Random.seed, envir=globalenv())
> sample(10)
 [1]  3 10  7  8  5  2  1  4  9  6

Hope this helps.

You could always just execute the sample(10) without setting the seed to return different samples if you are not concerned with setting a seed.

Community
  • 1
  • 1
Sean H
  • 267
  • 2
  • 6
  • If you set again the same seed you will get the same result on sample, if after rm(....) you don't set.seed then you will get a different sample – llrs Nov 03 '16 at 11:43
  • Perfect solution to my problem, thank you!!! – OpenSauce May 04 '20 at 08:54