Skip to content

Conversation

@leggettc18
Copy link
Contributor

@leggettc18 leggettc18 commented Nov 22, 2025

Apparently, std::random_device is not properly non-deterministic on certain situations where rng hardware is not accessible or something like that. I recently bumped into this with a Linux distro on my gaming desktop. So I essentially copied the randomizer rng to ShipUtils so I could use it for the Cosmetics Editor (with std::random_device it was always generating every color to the same dark blue color). It is a copy of the same functionality, it does not use the same seeds/state variables so randomizing cosmetics won't effect randomizer seed generation and vice/versa.

Build Artifacts

state = seed;
}

uint32_t ShipUtils_next32() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally random.cpp core functions would change to taking state as parameter, then these endpoints with globals could pass those into the core function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah if we want to shift Rando over to these funcs as well that's what I would do, trying to decide if that's in-scope for right now or not. I guess if I'm doing this on develop instead of dev-copper I might as well go all the way.

#if !defined(__SWITCH__) && !defined(__WIIU__)
uint64_t seed = static_cast<uint64_t>(std::random_device{}());
#else
uint64_t seed = static_cast<uint64_t>(std::hash<std::string>{}(std::to_string(rand())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint64_t seed = static_cast<uint64_t>(std::hash<std::string>{}(std::to_string(rand())));
uint64_t seed = static_cast<uint64_t>(rand());

Beyond this PR's scope, but we should go ahead & rely on rand without the string-then-hash song & dance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this was on dev-copper instead of dev I'd say it's probably out of scope but since its on dev I might as well go ahead and make the bigger changes, so I'm thinking this is maybe not quite out of scope after all.

@leggettc18 leggettc18 added the do not merge Not ready or not valid changes label Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge Not ready or not valid changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants