Languages
[Edit]
EN

C# / .NET - generate list with 10 random numbers

6 points
Created by:
Nabila-Burnett
385

Random.Next method + List<T> class example

public static class RandomUtils
{
	public static List<int> generateList(int count)
	{
		Random random = new Random();
		List<int> values = new List<int>();

		for (int i = 0; i < count; ++i)
			values.Add(random.Next());

		return values;
	}
}

Example:

List<int> values = RandomUtils.generateList(10);

foreach (int entry in values)
	Console.WriteLine(entry);

Output:

490485272
864820117
1495826699
1735587819
842228568
570809745
1432321477
1467935517
1356326042
1627623506

References

  1. List<T> Class - Microsoft Docs
  2. Random.Next Method - Microsoft Docs
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

C# / .NET - random

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join