C
C#2w ago
Dinosaure

✅ 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
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Dinosaure
Dinosaure2w ago
Hmm, I'll have a thought about that, thanks.
canton7
canton72w ago
Setting the seed explicitly alos has uses. And yep, you can get that seed from another Random
Dinosaure
Dinosaure2w ago
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?
canton7
canton72w ago
(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 ago
Dinosaure
Dinosaure2w ago
To 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
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Dinosaure
Dinosaure2w ago
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
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Dinosaure
Dinosaure2w ago
Yes, but that's a hassle on my end!
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Dinosaure
Dinosaure2w ago
I love when someone else has the responsibility for my storage. There is no problem though, thanks for the help. 🙂
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Dinosaure
Dinosaure2w ago
If Random.Current() was a thing, I'd not have to store the picked value on my side. 🙂
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Dinosaure
Dinosaure2w ago
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 rands 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. 👍
int graine = seed is null ? new Random().Next() : seed.Value;
Random rand = new(graine);
int graine = seed is null ? new Random().Next() : seed.Value;
Random rand = new(graine);
It works, thanks.
canton7
canton72w ago
int graine = seed ?? Random.Shared.Next();
Dinosaure
Dinosaure2w ago
Nice catch.
MODiX
MODiX2w ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server