Languages
[Edit]
EN

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

6 points
Created by:
JustMike
3491

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
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.