Skip to content

Actualize snippet example for Next() Method with rest of languages #9759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 34 additions & 23 deletions snippets/csharp/System/Random/Overview/next3.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
using System;
using System;

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

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

for (uint ctr = 1; ctr <= 10; ctr++)
Console.WriteLine($"{rnd.Next(),15:N0}");
if (!int.TryParse(line, out int numbers) || numbers <= 0)
{
numbers = 10;
}

// 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>
}
for (uint ctr = 1; ctr <= numbers; 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
// </Snippet5>
}
}