From 66855c684427dc536c3f321293230af11f135c4d Mon Sep 17 00:00:00 2001 From: WilliamAntonRohm Date: Fri, 20 Dec 2019 15:49:17 -0800 Subject: [PATCH 1/2] updating for Try .NET --- .../system.Random.Next/CS/next3.cs | 43 ++++++++++--------- .../system.Random/cs/booleans2.cs | 2 - 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.Random.Next/CS/next3.cs b/snippets/csharp/VS_Snippets_CLR_System/system.Random.Next/CS/next3.cs index 2fa34e7249a..02c26ebc410 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.Random.Next/CS/next3.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.Random.Next/CS/next3.cs @@ -1,10 +1,10 @@ -// -using System; +using System; public class Example { public static void Main() { + // Console.Write("Number of random numbers to generate: "); String line = Console.ReadLine(); uint numbers = 0; @@ -15,24 +15,25 @@ public static void Main() for (uint ctr = 1; ctr <= numbers; ctr++) Console.WriteLine("{0,15:N0}", rnd.Next()); + + // The example displays output like the following when asked to generate + // 15 random numbers: + // Number of random numbers to generate: 15 + // 1,733,189,596 + // 566,518,090 + // 1,166,108,546 + // 1,931,426,514 + // 1,341,108,291 + // 1,012,698,049 + // 890,578,409 + // 1,377,589,722 + // 2,108,384,181 + // 1,532,939,448 + // 762,207,767 + // 815,074,920 + // 1,521,208,785 + // 1,950,436,671 + // 1,266,596,666 + // } } -// The example displays output like the following when asked to generate -// 15 random numbers: -// Number of random numbers to generate: 15 -// 1,733,189,596 -// 566,518,090 -// 1,166,108,546 -// 1,931,426,514 -// 1,341,108,291 -// 1,012,698,049 -// 890,578,409 -// 1,377,589,722 -// 2,108,384,181 -// 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/VS_Snippets_CLR_System/system.Random/cs/booleans2.cs b/snippets/csharp/VS_Snippets_CLR_System/system.Random/cs/booleans2.cs index 68dc9e85f8b..178a4f59a33 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.Random/cs/booleans2.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.Random/cs/booleans2.cs @@ -2,7 +2,6 @@ public class Example { - public static void Main() { // @@ -35,6 +34,5 @@ bool NextBoolean() // Number of false values: 500,223 (50.022 %) // } - } From 7c637e9b5ab9640a29610c381b1e93084ac17b07 Mon Sep 17 00:00:00 2001 From: William Anton Rohm Date: Fri, 3 Jan 2020 09:00:23 -0800 Subject: [PATCH 2/2] Removed Readline dependency --- .../system.Random.Next/CS/next3.cs | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.Random.Next/CS/next3.cs b/snippets/csharp/VS_Snippets_CLR_System/system.Random.Next/CS/next3.cs index 02c26ebc410..b78ef1a84e9 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.Random.Next/CS/next3.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.Random.Next/CS/next3.cs @@ -5,29 +5,20 @@ public class Example public static void Main() { // - Console.Write("Number of random numbers to generate: "); - String line = Console.ReadLine(); - uint numbers = 0; Random rnd = new Random(); - if (! UInt32.TryParse(line, out numbers)) - numbers = 10; - - for (uint ctr = 1; ctr <= numbers; ctr++) - Console.WriteLine("{0,15:N0}", rnd.Next()); + Console.WriteLine("Generating 10 random numbers:"); + + 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 + // 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,341,108,291 - // 1,012,698,049 - // 890,578,409 - // 1,377,589,722 - // 2,108,384,181 // 1,532,939,448 // 762,207,767 // 815,074,920