Skip to content

SP4: Improve Generate randomness#3022

Merged
swharden merged 6 commits intoScottPlot:mainfrom
KroMignon:UpdateSeedGenerator
Nov 29, 2023
Merged

SP4: Improve Generate randomness#3022
swharden merged 6 commits intoScottPlot:mainfrom
KroMignon:UpdateSeedGenerator

Conversation

@KroMignon
Copy link
Contributor

Use a global Random number generator when seed is null to enforce values randomness. Should fix #2893

@swharden
Copy link
Member

Thanks for this improvement @KroMignon! This topic made me double-check what's going on in ScottPlot5's RandomDataGenerator class. It's using a System.Security.Cryptography.RandomNumberGenerator to generate the seed for Random(). I suspect this is thread safe and truly random, but if you have more familiar with this topic I'd appreciate any feedback you may have on this class

@swharden swharden merged commit ef206ba into ScottPlot:main Nov 29, 2023
@swharden swharden changed the title SP4: Improves Generate class. SP4: Improve Generate randomness Nov 29, 2023
@KroMignon
Copy link
Contributor Author

Thanks for merging my PR 😄

AFAIK, the only thread-safe random number generator in .NET is System.Random.Shared, which is available since .NET 6.
For all other random number generators, you should use ThreadLocal if you are using a static instance of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SP4: Improve Generate seeding

2 participants