# Random seed

**URL:** <https://forum.makecode.com/t/random-seed/1812>\
**Category:** Arcade\
**Created:** [April 23, 2020, 11:52pm UTC](https://forum.makecode.com/t/random-seed/1812 "2020-04-23T23:52:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob\_c](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jacob_c/32/1532_2.png) [@jacob\_c](https://forum.makecode.com/u/jacob_c)\
**Post date:** [April 23, 2020, 11:52pm UTC](https://forum.makecode.com/t/random-seed/1812/1 "2020-04-23T23:52:20Z")

</div>

Inspired by @shakao’s [awesome city skyline generator](https://forum.makecode.com/t/procedurally-generated-skyline/1782), I started playing around with a procedurally generated art project of my own.

As I’m writing it, I’m finding I want to be able to seed the random number generator with a specific value. Doing so would a) let me see a consistent result as I develop and b) let specific outcomes be more sharable if the seed was known…

I know JS’s Math.random doesn’t expose any seeded random support ([yet… Stage 1 proposal](https://github.com/tc39/proposal-seeded-random)), but I figured it’s possible you’ve already written your own random implementation anyway…

Is it technically possible today to seed the random number generator with a specific value? Do you think adding a block to support that would be useful?

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [April 24, 2020, 12:19am UTC](https://forum.makecode.com/t/random-seed/1812/2 "2020-04-24T00:19:10Z")

</div>

[https://github.com/microsoft/pxt-common-packages/pull/465](https://github.com/microsoft/pxt-common-packages/pull/465) fastrandom has that (though I believe at this point the class name is incredibly misleading, as it’s likely slower now than Math.random …) - I believe it’s still used in particle effects, but I may have switched them at some point. Worth noting it’s got a range of 0x0000 to 0xffff, if thats a deal breaker

I feel like I might’ve seen a PR re: adding the ability to seed random at some point but I’m not sure - it would probably have been mmoskal and would have been in pxt and/or pxt-common-packages (I’m on my phone, can look for it later).

If you want it for actually seeding things, you probably want the object oriented approach anyway - to keep things mostly consistent (avoid timing issues or things of the sort causing different behavior) you would likely need a different seeded random for each event / sprite / anything of the sort.

---

<div class="post-metadata">

**Author:** ![shakao](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/shakao/32/113_2.png) [@shakao](https://forum.makecode.com/u/shakao)\
**Post date:** [April 24, 2020, 3:11pm UTC](https://forum.makecode.com/t/random-seed/1812/3 "2020-04-24T15:11:31Z")

</div>

You might be thinking of this [https://github.com/microsoft/pxt-common-packages/pull/908](https://github.com/microsoft/pxt-common-packages/pull/908) which didn’t get merged in.

It definitely feels useful to me, for both reasons you mentioned as well as in an classroom context where a teacher might want to sync their students to the same result. I think it’s at least worth submitting an issue for, to keep it on the radar when we get back to Arcade features!

---

<div class="post-metadata">

**Author:** ![jacob\_c](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jacob_c/32/1532_2.png) [@jacob\_c](https://forum.makecode.com/u/jacob_c)\
**Post date:** [April 24, 2020, 4:20pm UTC](https://forum.makecode.com/t/random-seed/1812/4 "2020-04-24T16:20:59Z")

</div>

> it’s at least worth submitting an issue for

Will do
