Seed pc.math.random


#1

Hi

Does PlayCanvas provide a way to seed the random number generator?


#2

It uses the JS standard library of Math.random() which doesn’t have the API to seed.

Some Google searches recommends using a different generator like this: https://github.com/davidbau/seedrandom


#3

Okay, thanks.

To have a built-in generator with seeding would be a nice addition to PlayCanvas. We use that a lot with procedurally generated content that has to be replayable or work in a multiplayer environment.


#4

Is there a problem using an external generator? As far as I can tell, it doesn’t conflict with the PlayCanvas engine.


#5

No, it’s probably fine – haven’t looked into it yet :slightly_smiling_face:
I was just surprised this wasn’t supported out of the box in default Javascript (coming from a C# background).


#6

Ah, I see. I’m a little surprised too with the default JS implementation. My guess that PlayCanvas doesn’t package one into the engine due to potential bloat to the engine size and if they were, they would be using an open source one anyway as it’s a solved problem.