Uh oh!
There was an error while loading. Please reload this page.
Implement Shuffle, GetString, and GetItems on Random{NumberGenerator} - #78598
Conversation
ghost
commented
Nov 19, 2022
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
ghost
commented
Nov 19, 2022
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones Issue DetailsImplements:
This does both Closes #73864.
|
stephentoub
commented
Nov 19, 2022
Can you search around the repo and use these where it makes sense, e.g. etc? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
stephentoub
commented
Nov 20, 2022
A quick search suggests other opportunities, e.g. |
I excluded searching in |
vcsjones
commented
Nov 20, 2022
I checked in a few more. Several of them I left unchanged because they have configurations that build for NetCoreAppMinimum or NetFramework. It didn't make sense to |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Benjamin Moir <DaZombieKiller@users.noreply.github.com> Co-authored-by: Theodore Tsirpanis <teo@tsirpanis.gr> Co-authored-by: Michał Petryka <35800402+MichalPetryka@users.noreply.github.com>
vcsjones
commented
Nov 20, 2022
Sorry for the force push. I goofed on |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Dan Moseley <danmose@microsoft.com>
stephentoub
commented
Jan 4, 2023
@vcsjones, when you get a chance, could you take a look at the pending comments/questions? Then we can get this merged. Thanks. |
Uh oh!
There was an error while loading. Please reload this page.
| for (int i = 0; i < destination.Length; i++) | ||
| { | ||
| destination[i] = choices[GetInt32(choices.Length)]; | ||
| } |
There was a problem hiding this comment.
Similar to the N virtual calls concern in System.Random, it might be useful to change this to do something like
Span<byte>randomBytes=stackallocbyte[128];Span<int>randomIntStorage=stackallocint[randomBytes.Length/sizeof(int)];intrandomInts=0;for(inti=destination.Length-1;i>=0;i--){while(randomInts<=0){if(i<randomIntStorage.Length){randomBytes=randomBytes.Slice(0,i*sizeof(int));}Fill(randomBytes);randomInts=FilterInt32(randomBytes,randomIntStorage);}randomInts--;destination[i]=choices[randomInts[randomInts]];}to reduce P/Invokes by a factor of randomIntStorage.Length.
Though that requires writing FilterInt32, and the complexity of above, so it should be checked to see if the perf justifies it.
(This is an idea for later, not a "right now")
…/Cryptography/RandomNumberGenerator.cs Co-authored-by: Jeremy Barton <jbarton@microsoft.com>
davidfowl
commented
Jan 13, 2023
Very nice APIs! I wonder if we should have |
Concept seems reasonable, though to nit pick, to match the other APIs we'd probably want it to be called GetItem rather than PickRandom. Can you open a separate issue? Are there places it would be used in ASP.NET? I assume this is essentially shorthand for: |
I can.
Not sure, I was building something with YARP when this came up. Also would be used here
Yep! |
davidfowl
commented
Jan 14, 2023
Filed an issue here |
Implements:
Random.GetItemsRandom.ShuffleRandomNumberGenerator.GetStringRandomNumberGenerator.GetHexStringRandomNumberGenerator.ShuffleThis does both
RandomNumberGeneratorandRandomin one go. If folks prefer I can split the PR.Closes#73864.