Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8497311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:05:35+00:00 2026-06-11T00:05:35+00:00

According to MSDN documentation for RandomNumberGenerator : Application code does not directly use this

  • 0

According to MSDN documentation for RandomNumberGenerator:

Application code does not directly use this class. This abstract class is provided as the base class for all cryptographic random number generators.

For an implementation of a cryptographic random number generator, use the derived class RNGCryptoServiceProvider.

However, I have seen the following code used on a few occassions in different code bases:

byte[] bytes = new byte[...];
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(bytes);

Most notably with StackExchange (which I assume includes SO) and also with BCrypt.Net.

Therefore, I am a little confused – what type of RandomNumberGenerator is the above code returning? Also is it a bit of a flaw that some code bases are using RandomNumberGenerator rather than RNGCryptoServiceProvider?

I assume RandomNumberGenerator.Create() is doing under the hood which I am completely missing here, but technically (as it’s an abstract class) shouldn’t the above code throw an error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:05:36+00:00Added an answer on June 11, 2026 at 12:05 am

    The RandomNumberGenerator.Create() method calls RandomNumberGenerator.Create("System.Security.Cryptography.RandomNumberGenerator"), which will eventually create an instance of RNGCryptoServiceProvider.

    (It does some lookups in a pair of dictionaries, so it’s likely that you can change the behaviour of that call by registering a default random generator somewhere.)

    The actual type of the object returned is not known at compile time, it’s only known that it will inherit the RandomNumberGenerator class, so you can use a RandomNumberGenerator reference variable for it.

    This way of creating different types of instances depending on the input is used in a couple of places in the framework, for example by the WebRequest.Create method.


    Someone at Micrsoft has “fixed” the current documentation (framework 4.5) for the Create() method. It now says:

    “When overridden in a derived class, creates an instance of the
    default implementation of a cryptographic random number generator that
    can be used to generate random data.”

    The documentation for framework 4.0 says:

    “Creates an instance of the default implementation of a cryptographic
    random number generator that can be used to generate random data.”

    This is the correct description of what the method does. I will put in a request to put that description back in the newer documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According MSDN, FxCop is an application that analyzes managed code assemblies (code that targets
According to the MSDN documentation ( http://msdn.microsoft.com/en-us/library/ms172987.aspx ), the My.Application.Log property is used to
According to the MSDN documentation on the List<T>.Clear method : This method is an
According the the MSDN documentation, the following code should output '5' to the console
MSDN documentation says that instance methods, which includes Stream.Write, of Stream class are not
In my current production code, and according to documentation on msdn , the way
According to the MSDN documentation for the RSA class there are two RSA.Create() methods
According to MSDN documentation this proc is supposed to grant login to a windows
According to MSDN documentation it is not possible to set Socket.SendTimeout to a value
According to the MSDN documentation the this pointer is stored in ECX when using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.