Fixing set.seed for an entire session

后端 未结 6 1586
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 01:59

I am using R to construct an agent based model with a monte carlo process. This means I got many functions that use a random engine of some kind. In order to get reproducibl

6条回答
  •  自闭症患者
    2020-12-09 02:42

    If you want to always return the same results from random processes, simply keep the seed set all the time with:

    addTaskCallback(function(...) {set.seed(123);TRUE})
    

    Now the output is the same every time:

    print(sample(1:10,3))
    # [1] 3 8 4
    print(sample(1:10,3))
    # [1] 3 8 4
    

提交回复
热议问题