-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
21 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Example.Main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters