✅ random current value?
Hello, I'm using a naïve Random generator, and I'd want to display the current seed used, in the hope to replicate the current state for some later replay.
How can I achieve that, apart from having a second Random seeding its
.Next()
int to the actual Random?19 Replies
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Hmm, I'll have a thought about that, thanks.
Setting the seed explicitly alos has uses. And yep, you can get that seed from another Random
Yeah, basically, what I told in the opening: getting a "seeding seed" that I borrow (and save) to be used as actual seed.
That's not that much inconvenient, but isn't it possible to get the
.Current
value of a random?(although use
Random.Shared.Next()
to avoid newing up a new instance)
Well, the internal state is an implementaiton detail, and in fact the amount of state which is stored got changed a few .NET versions agoTo be fair, I already have the seeding in place:
Random rand = seed is null ? new() : new(seed.Value);
, just in that "non-seeded" case, I'd want to borrow the value.
It'll be a random seed buffer then.
Yeah, I've seen that...
public Random() => /*[..]*/ _impl = GetType() == typeof(Random) ? new XoshiroImpl() : new Net5CompatDerivedImpl(this);
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
That's totally what I call a random buffer, not in the randomness sense but in buffer name use. 😄
I'd wish I could just
.Current()
to get the current value tho.Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Yes, but that's a hassle on my end!
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
I love when someone else has the responsibility for my storage.
There is no problem though, thanks for the help. 🙂
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
If
Random.Current()
was a thing, I'd not have to store the picked value on my side. 🙂Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Yea, the value source doesn't really matter, I may use any source I'd wish as a source for
.Next
.
LPlateau[i] = new(this, new(i_x, i_y), (rand.Next(iMax - i) < mines - minées) && minées == minées++); //Référencement de la case
It's actually used here (and only there), at lPlateau
initialization, in a foreach loop.
I know this is a bit hard to read, but there's the lowest I could get to not having rand
s everywhere on multiple lines.
So, when no seed is set as a base, I'll generate one, and use it as a (spoofed) set down the line. 👍
It works, thanks.int graine = seed ?? Random.Shared.Next();
Nice catch.
If you have no further questions, please use /close to mark the forum thread as answered