Skip to content

Commit 1fa2642

Browse files
Update Random.xml (#3855)
* Update Random.xml Add information that the default seed value in .NET Core is randomized * Apply suggestions from code review Co-Authored-By: Genevieve Warren <[email protected]> Co-authored-by: Genevieve Warren <[email protected]>
1 parent e7251d9 commit 1fa2642

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

xml/System/Random.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@
7777
7878
- The <xref:System.Random.%23ctor%28System.Int32%29> constructor uses an explicit seed value that you supply.
7979
80-
- The <xref:System.Random.%23ctor> constructor uses the system clock to provide a seed value. This is the most common way of instantiating the random number generator.
80+
- The <xref:System.Random.%23ctor> constructor uses the default seed value. This is the most common way of instantiating the random number generator.
81+
82+
In .NET Framework, the default seed value is time-dependent. In .NET Core, the default seed value is produced by the thread-static, pseudo-random number generator.
8183
8284
If the same seed is used for separate <xref:System.Random> objects, they will generate the same series of random numbers. This can be useful for creating a test suite that processes random values, or for replaying games that derive their data from random numbers. However, note that <xref:System.Random> objects in processes running under different versions of the .NET Framework may return different series of random numbers even if they're instantiated with identical seed values.
8385
@@ -373,13 +375,14 @@ Random.NextDouble() * (maxValue - minValue) + minValue
373375
</AssemblyInfo>
374376
<Parameters />
375377
<Docs>
376-
<summary>Initializes a new instance of the <see cref="T:System.Random" /> class, using a time-dependent default seed value.</summary>
378+
<summary>Initializes a new instance of the <see cref="T:System.Random" /> class using a default seed value.</summary>
377379
<remarks>
378380
<format type="text/markdown"><![CDATA[
379381
380382
## Remarks
383+
In .NET Framework, the default seed value is derived from the system clock, which has finite resolution. As a result, different <xref:System.Random> objects that are created in close succession by a call to the parameterless constructor have identical default seed values and, therefore, produce identical sets of random numbers. You can avoid this problem by using a single <xref:System.Random> object to generate all random numbers. You can also work around it by generating your own random seed value and passing it to the <xref:System.Random.%23ctor%28System.Int32%29> constructor. For more information, see the <xref:System.Random.%23ctor%28System.Int32%29> constructor.
381384
382-
The default seed value is derived from the system clock, which has finite resolution. As a result, on the .NET Framework only, different <xref:System.Random> objects that are created in close succession by a call to the parameterless constructor will have identical default seed values and, therefore, will produce identical sets of random numbers. This problem can be avoided by using a single <xref:System.Random> object to generate all random numbers. You can also work around it by generating your own random seed value and passing it to the <xref:System.Random.%23ctor%28System.Int32%29> constructor. For more information, see the <xref:System.Random.%23ctor%28System.Int32%29> constructor. Note that this limitation does not apply to .NET Core.
385+
In .NET Core, the default seed value is produced by the thread-static, pseudo-random number generator, so the previously described limitation does not apply. Different <xref:System.Random> objects created in close succession produce different sets of random numbers in .NET Core.
383386
384387
Call this constructor if you want your random number generator to generate a random sequence of numbers. To generate a fixed sequence of random numbers that will be the same for different random number generators, call the <xref:System.Random.%23ctor%28System.Int32%29> constructor with a fixed seed value . This <xref:System.Random> constructor overload is frequently used when testing apps that use random numbers.
385388

0 commit comments

Comments
 (0)