Runtime: RNGCryptoServiceProvider offers unappropriate API

Created on 22 Jul 2019  路  5Comments  路  Source: dotnet/runtime

The RNGCryptoServiceProvider should have an API that provides all the convenience methods of the standard Random class. It looks ridiculous having an example code snippet that is 34 lines longer than necessary.

If there were a decorator class providing the NextInt functions for rolling a dice or selecting a random element from an array or collection, many of the Stack Overflow answers could be written with a reasonable amount of code. As it is now, there is actual danger of people using the secure random number generator and then forgetting about the bias, just because they don't want to copy and paste the boilerplate code from this example.

This boilerplate code should be implemented exactly once, in the .NET standard library, and not millions of times by inexperienced programmers in a hurry of meeting a deadline.

References:

area-System.Security documentation

Most helpful comment

@danmosemsft Thanks for the offer, but no. It's Microsoft's job to fix the documentation. And I don't write C#, Visual Basic and F# and assembly fluently to correct all of them. I strongly believe that these example snippets are all generated from a common template, otherwise this job would be really frustratingly boring and error-prone, and I cannot believe Microsoft is living _that far_ in the past.

All 5 comments

GetInt32 was added to System.Security.Cryptography.RandomNumberGenerator and will be available in .NET Core 3 and .NET Standard 2.1. Does this provide the solution you were looking for?

https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.randomnumbergenerator.getint32?view=netcore-3.0

Partly. The documentation is still bloated. The documentation still needs to be adjusted to use this shiny new API. Having bloated code in the API documentation makes the API team look bad for no reason.

@bartonjs is going through our API docs I believe.

@danmosemsft Thanks for the offer, but no. It's Microsoft's job to fix the documentation. And I don't write C#, Visual Basic and F# and assembly fluently to correct all of them. I strongly believe that these example snippets are all generated from a common template, otherwise this job would be really frustratingly boring and error-prone, and I cannot believe Microsoft is living _that far_ in the past.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

btecu picture btecu  路  3Comments

noahfalk picture noahfalk  路  3Comments

omajid picture omajid  路  3Comments

bencz picture bencz  路  3Comments

v0l picture v0l  路  3Comments