Skip to content

Commit 9063bf4

Browse files
authored
Fixup RandomNumberGenerator (#8023)
1 parent 018d025 commit 9063bf4

File tree

1 file changed

+60
-58
lines changed

1 file changed

+60
-58
lines changed

xml/System.Security.Cryptography/RandomNumberGenerator.xml

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@
5858
</Attribute>
5959
</Attributes>
6060
<Docs>
61-
<summary>Represents the abstract class from which all implementations of cryptographic random number generators derive.</summary>
61+
<summary>Provides functionality for generating random values.</summary>
6262
<remarks>
63-
<format type="text/markdown"><![CDATA[
64-
65-
## Remarks
63+
<format type="text/markdown"><![CDATA[
64+
65+
## Remarks
6666
Cryptographic random number generators create cryptographically strong random values.
6767
68+
Using the static members of this class is the preferred way to generate random values.
69+
6870
To create a random number generator, call the @System.Security.Cryptography.RandomNumberGenerator.Create method. This is preferred over calling the constructor of the derived class @System.Security.Cryptography.RNGCryptoServiceProvider, which is not available on all platforms.
6971
]]></format>
7072
</remarks>
@@ -113,11 +115,11 @@ To create a random number generator, call the @System.Security.Cryptography.Rand
113115
<Docs>
114116
<summary>Initializes a new instance of <see cref="T:System.Security.Cryptography.RandomNumberGenerator" />.</summary>
115117
<remarks>
116-
<format type="text/markdown"><![CDATA[
117-
118-
## Remarks
119-
You cannot create an instance of an abstract class. Application code will create a new instance of a derived class. For an implementation of a cryptographic random number generator, use the derived class <xref:System.Security.Cryptography.RNGCryptoServiceProvider>.
120-
118+
<format type="text/markdown"><![CDATA[
119+
120+
## Remarks
121+
You cannot create an instance of an abstract class. Application code will create a new instance of a derived class. For an implementation of a cryptographic random number generator, use the derived class <xref:System.Security.Cryptography.RNGCryptoServiceProvider>.
122+
121123
]]></format>
122124
</remarks>
123125
<related type="Article" href="/dotnet/standard/security/cryptographic-services">Cryptographic Services</related>
@@ -303,16 +305,16 @@ To create a random number generator, call the @System.Security.Cryptography.Rand
303305
<Docs>
304306
<summary>When overridden in a derived class, releases all resources used by the current instance of the <see cref="T:System.Security.Cryptography.RandomNumberGenerator" /> class.</summary>
305307
<remarks>
306-
<format type="text/markdown"><![CDATA[
307-
308-
## Remarks
309-
Call `Dispose` when you are finished using the <xref:System.Security.Cryptography.RandomNumberGenerator>. The `Dispose` method leaves the <xref:System.Security.Cryptography.RandomNumberGenerator> in an unusable state. After calling `Dispose`, you must release all references to the <xref:System.Security.Cryptography.RandomNumberGenerator> so the garbage collector can reclaim the memory that the <xref:System.Security.Cryptography.RandomNumberGenerator> was occupying.
310-
311-
For more information, see [Cleaning Up Unmanaged Resources](/dotnet/standard/garbage-collection/unmanaged) and [Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose).
312-
308+
<format type="text/markdown"><![CDATA[
309+
310+
## Remarks
311+
Call `Dispose` when you are finished using the <xref:System.Security.Cryptography.RandomNumberGenerator>. The `Dispose` method leaves the <xref:System.Security.Cryptography.RandomNumberGenerator> in an unusable state. After calling `Dispose`, you must release all references to the <xref:System.Security.Cryptography.RandomNumberGenerator> so the garbage collector can reclaim the memory that the <xref:System.Security.Cryptography.RandomNumberGenerator> was occupying.
312+
313+
For more information, see [Cleaning Up Unmanaged Resources](/dotnet/standard/garbage-collection/unmanaged) and [Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose).
314+
313315
> [!NOTE]
314-
> Always call `Dispose` before you release your last reference to the <xref:System.Security.Cryptography.RandomNumberGenerator>. Otherwise, the resources it is using will not be freed until the garbage collector calls the <xref:System.Security.Cryptography.RandomNumberGenerator> object's `Finalize` method.
315-
316+
> Always call `Dispose` before you release your last reference to the <xref:System.Security.Cryptography.RandomNumberGenerator>. Otherwise, the resources it is using will not be freed until the garbage collector calls the <xref:System.Security.Cryptography.RandomNumberGenerator> object's `Finalize` method.
317+
316318
]]></format>
317319
</remarks>
318320
</Docs>
@@ -361,19 +363,19 @@ To create a random number generator, call the @System.Security.Cryptography.Rand
361363
<see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</param>
362364
<summary>When overridden in a derived class, releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.RandomNumberGenerator" /> and optionally releases the managed resources.</summary>
363365
<remarks>
364-
<format type="text/markdown"><![CDATA[
365-
366-
## Remarks
367-
This method is called by the public `Dispose()` method and the `Finalize` method. `Dispose()` invokes the protected `Dispose(Boolean)` method with the `disposing` parameter set to `true`. `Finalize` invokes `Dispose` with `disposing` set to `false`.
368-
369-
When the `disposing` parameter is `true`, this method releases all resources held by any managed objects that this <xref:System.Security.Cryptography.RandomNumberGenerator> references. This method invokes the `Dispose()` method of each referenced object.
370-
366+
<format type="text/markdown"><![CDATA[
367+
368+
## Remarks
369+
This method is called by the public `Dispose()` method and the `Finalize` method. `Dispose()` invokes the protected `Dispose(Boolean)` method with the `disposing` parameter set to `true`. `Finalize` invokes `Dispose` with `disposing` set to `false`.
370+
371+
When the `disposing` parameter is `true`, this method releases all resources held by any managed objects that this <xref:System.Security.Cryptography.RandomNumberGenerator> references. This method invokes the `Dispose()` method of each referenced object.
372+
371373
]]></format>
372374
</remarks>
373375
<block subset="none" type="overrides">
374376
<para>
375-
<see langword="Dispose" /> can be called multiple times by other objects. When overriding <see langword="Dispose(Boolean)" />, be careful not to reference objects that have been previously disposed in an earlier call to <see langword="Dispose" />. For more information about how to implement <see langword="Dispose(Boolean)" />, see [Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose).
376-
377+
<see langword="Dispose" /> can be called multiple times by other objects. When overriding <see langword="Dispose(Boolean)" />, be careful not to reference objects that have been previously disposed in an earlier call to <see langword="Dispose" />. For more information about how to implement <see langword="Dispose(Boolean)" />, see [Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose).
378+
377379
For more information about <see langword="Dispose" /> and <see langword="Finalize" />, see [Cleaning Up Unmanaged Resources](/dotnet/standard/garbage-collection/unmanaged).</para>
378380
</block>
379381
<related type="Article" href="/dotnet/standard/security/cryptographic-services">Cryptographic Services</related>
@@ -471,18 +473,18 @@ To create a random number generator, call the @System.Security.Cryptography.Rand
471473
<param name="data">The array to fill with cryptographically strong random bytes.</param>
472474
<summary>When overridden in a derived class, fills an array of bytes with a cryptographically strong random sequence of values.</summary>
473475
<remarks>
474-
<format type="text/markdown"><![CDATA[
475-
476-
## Remarks
476+
<format type="text/markdown"><![CDATA[
477+
478+
## Remarks
477479
The length of the byte array determines how many random bytes are produced.
478-
479-
## Examples
480-
The following example creates a random sequence 100 bytes long and stores it in `random`.
481-
480+
481+
## Examples
482+
The following example creates a random sequence 100 bytes long and stores it in `random`.
483+
482484
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetBytes Example/CPP/source.cpp" id="Snippet1":::
483485
:::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/RandomNumberGenerator/GetBytes/source.cs" id="Snippet1":::
484-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetBytes Example/VB/source.vb" id="Snippet1":::
485-
486+
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetBytes Example/VB/source.vb" id="Snippet1":::
487+
486488
]]></format>
487489
</remarks>
488490
<related type="Article" href="/dotnet/standard/security/cryptographic-services">Cryptographic Services</related>
@@ -648,15 +650,15 @@ To create a random number generator, call the @System.Security.Cryptography.Rand
648650
<summary>Generates a random integer between 0 (inclusive) and a specified exclusive upper bound using a cryptographically strong random number generator.</summary>
649651
<returns>A random integer between 0 (inclusive) and <paramref name="toExclusive" /> (exclusive).</returns>
650652
<remarks>
651-
<format type="text/markdown"><![CDATA[
652-
653-
## Remarks
654-
653+
<format type="text/markdown"><![CDATA[
654+
655+
## Remarks
656+
655657
The upper bound is exclusive to enable passing in a length value from an array, span, or list.
656658
Because it is an exclusive upper bound this method can never generate <xref:System.Int32.MaxValue?displayProperty=nameWithType>.
657659
658660
This method uses a discard-and-retry strategy to avoid the low value bias that a simple modular arithmetic operation would produce.
659-
661+
660662
]]></format>
661663
</remarks>
662664
<exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="toExclusive" /> parameter is less than or equal to 0.</exception>
@@ -698,17 +700,17 @@ To create a random number generator, call the @System.Security.Cryptography.Rand
698700
<summary>Generates a random integer between a specified inclusive lower bound and a specified exclusive upper bound using a cryptographically strong random number generator.</summary>
699701
<returns>A random integer between <paramref name="fromInclusive" /> (inclusive) and <paramref name="toExclusive" /> (exclusive).</returns>
700702
<remarks>
701-
<format type="text/markdown"><![CDATA[
702-
703-
## Remarks
704-
703+
<format type="text/markdown"><![CDATA[
704+
705+
## Remarks
706+
705707
The upper bound is exclusive to enable passing in a length value from an array, span, or list.
706708
Because it is an exclusive upper bound this method can never generate <xref:System.Int32.MaxValue?displayProperty=nameWithType>.
707709
708710
This method uses a discard-and-retry strategy to avoid the low value bias that a simple modular arithmetic operation would produce.
709711
710712
Negative values are permitted for both `fromInclusive` and `toExclusive`.
711-
713+
712714
]]></format>
713715
</remarks>
714716
<exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="toExclusive" /> parameter is less than or equal to the <paramref name="fromInclusive" /> parameter.</exception>
@@ -760,20 +762,20 @@ To create a random number generator, call the @System.Security.Cryptography.Rand
760762
<param name="data">The array to fill with cryptographically strong random nonzero bytes.</param>
761763
<summary>When overridden in a derived class, fills an array of bytes with a cryptographically strong random sequence of nonzero values.</summary>
762764
<remarks>
763-
<format type="text/markdown"><![CDATA[
764-
765-
## Remarks
766-
The length of the byte array determines how many random bytes are produced.
767-
768-
769-
770-
## Examples
771-
The following example creates a random sequence of 100 nonzero bytes and stores it in `random`.
772-
765+
<format type="text/markdown"><![CDATA[
766+
767+
## Remarks
768+
The length of the byte array determines how many random bytes are produced.
769+
770+
771+
772+
## Examples
773+
The following example creates a random sequence of 100 nonzero bytes and stores it in `random`.
774+
773775
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetNonZeroBytes Example/CPP/source.cpp" id="Snippet1":::
774776
:::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/RandomNumberGenerator/GetNonZeroBytes/source.cs" id="Snippet1":::
775-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetNonZeroBytes Example/VB/source.vb" id="Snippet1":::
776-
777+
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic RandomNumberGenerator.GetNonZeroBytes Example/VB/source.vb" id="Snippet1":::
778+
777779
]]></format>
778780
</remarks>
779781
<related type="Article" href="/dotnet/standard/security/cryptographic-services">Cryptographic Services</related>

0 commit comments

Comments
 (0)