# Random function calculation

**URL:** <https://discuss.pytorch.org/t/random-function-calculation/21061>\
**Category:** Uncategorized\
**Created:** [July 12, 2018, 12:47pm UTC](https://discuss.pytorch.org/t/random-function-calculation/21061 "2018-07-12T12:47:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shani\_Gamrian](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/shani_gamrian/32/1299_2.png) [@Shani\_Gamrian](https://discuss.pytorch.org/u/Shani_Gamrian)\
**Post date:** [July 12, 2018, 12:47pm UTC](https://discuss.pytorch.org/t/random-function-calculation/21061/1 "2018-07-12T12:47:05Z")

</div>

How does the random function calculation depend on the seed? What If I used seed=1 and now I want different values, does it matter whether I choose seed=2 or seed=300 next?

---

<div class="post-metadata">

**Author:** ![tom](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tom/32/3162_2.png) [@tom](https://discuss.pytorch.org/u/tom)\
**Post date:** [July 12, 2018, 1:57pm UTC](https://discuss.pytorch.org/t/random-function-calculation/21061/2 "2018-07-12T13:57:44Z")

</div>

If you’re not too worried over the quality of randomness, you could just use seed = 2 etc.  
If you run it sequentially, one way to be sure is to save the last seed(s) and continue from them. Or you could estimate the number of random calls and do them as warm up. It is [really easy to make mistakes when trying to be clever](https://www.johndcook.com/blog/2016/01/29/random-number-generator-seed-mistakes/), and I must admit that I’ve certainly come close to making the mistake described there thinking that it looks like a good idea at first sight.

Best regards

Thomas

---

<div class="post-metadata">

**Author:** ![Shani\_Gamrian](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/shani_gamrian/32/1299_2.png) [@Shani\_Gamrian](https://discuss.pytorch.org/u/Shani_Gamrian)\
**Post date:** [July 12, 2018, 2:03pm UTC](https://discuss.pytorch.org/t/random-function-calculation/21061/3 "2018-07-12T14:03:14Z")

</div>

I meant, is there a difference between choosing seed=2 and seed=300 after seed=1? For example, maybe seed=2 somehow generate numbers that are close to the ones generated when seed=1.

---

<div class="post-metadata">

**Author:** ![tom](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tom/32/3162_2.png) [@tom](https://discuss.pytorch.org/u/tom)\
**Post date:** [July 13, 2018, 6:15am UTC](https://discuss.pytorch.org/t/random-function-calculation/21061/4 "2018-07-13T06:15:44Z")

</div>

In answering a question, John Cook writes:

> [@](#):
>
> A high quality random number generator should produce uncorrelated output for any two different seeds, including consecutive seeds, and as far as anyone knows, the Mersenne Twister does this.

So as far as we know, it’s OK for CPU and without looking into it, I would guess that the GPU RNG also qualifies.

Best regards

Thomas

---

<div class="post-metadata">

**Author:** ![Shani\_Gamrian](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/shani_gamrian/32/1299_2.png) [@Shani\_Gamrian](https://discuss.pytorch.org/u/Shani_Gamrian)\
**Post date:** [July 13, 2018, 7:27am UTC](https://discuss.pytorch.org/t/random-function-calculation/21061/5 "2018-07-13T07:27:57Z")

</div>

Great, thank you! 🙂
