Skip to content

Commit

Permalink
remove console.readline (#10742)
Browse files Browse the repository at this point in the history
  • Loading branch information
gewarren authored Dec 10, 2024
1 parent acb8274 commit fac2678
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 35 deletions.
1 change: 1 addition & 0 deletions snippets/csharp/System/Random/Overview/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Example.Main();
47 changes: 17 additions & 30 deletions snippets/csharp/System/Random/Overview/next3.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
using System;

public class Example
public class Example
{
public static void Main()
{
// <Snippet5>
Console.Write("Number of random numbers to generate: ");

string? line = Console.ReadLine();
Random rnd = new Random();
Console.WriteLine("Generating 10 random numbers:");

if (!int.TryParse(line, out int numbers) || numbers <= 0)
{
numbers = 10;
}
Random rnd = new();

for (uint ctr = 1; ctr <= numbers; ctr++)
for (uint ctr = 1; ctr <= 10; ctr++)
Console.WriteLine($"{rnd.Next(),15:N0}");

// The example displays output like the following when asked to generate
// 15 random numbers:
// Number of random numbers to generate: 15
// 367 920 603
// 1 143 790 667
// 1 360 963 275
// 1 851 697 775
// 248 956 796
// 1 009 615 458
// 1 617 743 155
// 1 821 609 652
// 1 661 761 949
// 477 300 794
// 288 418 129
// 425 371 492
// 1 558 147 880
// 1 473 704 017
// 777 507 489
// The example displays output like the following:
//
// Generating 10 random numbers:
// 1,733,189,596
// 566,518,090
// 1,166,108,546
// 1,931,426,514
// 1,532,939,448
// 762,207,767
// 815,074,920
// 1,521,208,785
// 1,950,436,671
// 1,266,596,666
// </Snippet5>
}
}
2 changes: 1 addition & 1 deletion snippets/csharp/System/Random/Overview/project.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<OutputType>exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
6 changes: 2 additions & 4 deletions xml/System/Random.xml
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,8 @@ The following example uses the parameterless constructor to instantiate three <x
## Remarks
<xref:System.Random.Next%2A?displayProperty=nameWithType> generates a random number whose value ranges from 0 to less than <xref:System.Int32.MaxValue?displayProperty=nameWithType>. To generate a random number whose value ranges from 0 to some other positive number, use the <xref:System.Random.Next%28System.Int32%29?displayProperty=nameWithType> method overload. To generate a random number within a different range, use the <xref:System.Random.Next%28System.Int32%2CSystem.Int32%29?displayProperty=nameWithType> method overload.
## Examples
The following example makes repeated calls to the <xref:System.Random.Next%2A> method to generate a specific number of random numbers requested by the user. The <xref:System.Console.ReadLine%2A?displayProperty=nameWithType> method is used to get customer input.
The following example makes repeated calls to the <xref:System.Random.Next%2A> method to generate 10 random numbers.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random.Next/CPP/next3.cpp" id="Snippet5":::
:::code language="csharp" source="~/snippets/csharp/System/Random/Overview/next3.cs" interactive="try-dotnet-method" id="Snippet5":::
Expand All @@ -500,7 +498,7 @@ The following example uses the parameterless constructor to instantiate three <x
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>Starting with the .NET Framework version 2.0, if you derive a class from <see cref="T:System.Random" /> and override the <see cref="M:System.Random.Sample" /> method, the distribution provided by the derived class implementation of the <see cref="M:System.Random.Sample" /> method is not used in calls to the base class implementation of the <see cref="M:System.Random.Next" /> method. Instead, the uniform distribution returned by the base <see cref="T:System.Random" /> class is used. This behavior improves the overall performance of the <see cref="T:System.Random" /> class. To modify this behavior to call the <see cref="M:System.Random.Sample" /> method in the derived class, you must also override the <see cref="M:System.Random.Next" /> method.</para>
<para>If you derive a class from <see cref="T:System.Random" /> and override the <see cref="M:System.Random.Sample" /> method, the distribution provided by the derived class implementation of the <see cref="M:System.Random.Sample" /> method is not used in calls to the base class implementation of the <see cref="M:System.Random.Next" /> method. Instead, the uniform distribution returned by the base <see cref="T:System.Random" /> class is used. This behavior improves the overall performance of the <see cref="T:System.Random" /> class. To modify this behavior to call the <see cref="M:System.Random.Sample" /> method in the derived class, you must also override the <see cref="M:System.Random.Next" /> method.</para>
</block>
<altmember cref="T:System.Int32" />
</Docs>
Expand Down

0 comments on commit fac2678

Please sign in to comment.