Facepunch / sbox-issues

173 stars 11 forks source link

Inconsistent use of Random across helper functions #6115

Open Willco2 opened 1 month ago

Willco2 commented 1 month ago

What it is?

Color.Random uses SandboxSystem.Random that can be manually seeded by user code when needed. Sphere.RandomPointOnEdge uses Random.Shared instead, which can't. There are probably more examples as well.

What should it be?

Use SandboxSystem.Random across all helper functions, so manually setting a seed actually works.

MD485 commented 1 month ago

Weren't these functions added recently for emission within models for particle emitters? I don't actually see a problem for purposes like that having that disparity.

If any of the particle code is running in an async and/or an inconsistently ordered context (I remember there were issues with script ordering at some point) then having ThreadSafeRandom as opposed to Random would be preferrable.

image It seems like it's necessary to have those methods written that way to facilitate that functionality?

There can be valid reasons to have two methods in practice, but the decision to use Random.Shared doesn't seem to be done haphazardly.