diff --git a/snippets/csharp/System/Random/Overview/Program.cs b/snippets/csharp/System/Random/Overview/Program.cs new file mode 100644 index 00000000000..5a31894d3c4 --- /dev/null +++ b/snippets/csharp/System/Random/Overview/Program.cs @@ -0,0 +1 @@ +Example.Main(); diff --git a/snippets/csharp/System/Random/Overview/next3.cs b/snippets/csharp/System/Random/Overview/next3.cs index cbc7fc6c88a..4af4adf2650 100644 --- a/snippets/csharp/System/Random/Overview/next3.cs +++ b/snippets/csharp/System/Random/Overview/next3.cs @@ -1,41 +1,28 @@ -using System; - -public class Example +public class Example { public static void Main() { // - 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 // } } diff --git a/snippets/csharp/System/Random/Overview/project.csproj b/snippets/csharp/System/Random/Overview/project.csproj index 00e2eb9594d..b6c877752cd 100644 --- a/snippets/csharp/System/Random/Overview/project.csproj +++ b/snippets/csharp/System/Random/Overview/project.csproj @@ -1,7 +1,7 @@ - Library + exe net8.0 enable enable diff --git a/xml/System/Random.xml b/xml/System/Random.xml index 07b6235d72f..4715d408f96 100644 --- a/xml/System/Random.xml +++ b/xml/System/Random.xml @@ -481,10 +481,8 @@ The following example uses the parameterless constructor to instantiate three generates a random number whose value ranges from 0 to less than . To generate a random number whose value ranges from 0 to some other positive number, use the method overload. To generate a random number within a different range, use the method overload. - - ## Examples - The following example makes repeated calls to the method to generate a specific number of random numbers requested by the user. The method is used to get customer input. + The following example makes repeated calls to the 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"::: @@ -500,7 +498,7 @@ The following example uses the parameterless constructor to instantiate three - Starting with the .NET Framework version 2.0, if you derive a class from and override the method, the distribution provided by the derived class implementation of the method is not used in calls to the base class implementation of the method. Instead, the uniform distribution returned by the base class is used. This behavior improves the overall performance of the class. To modify this behavior to call the method in the derived class, you must also override the method. + If you derive a class from and override the method, the distribution provided by the derived class implementation of the method is not used in calls to the base class implementation of the method. Instead, the uniform distribution returned by the base class is used. This behavior improves the overall performance of the class. To modify this behavior to call the method in the derived class, you must also override the method.