I have a list private List<HeroStats> allHeroes;
and a list private List<Team> allTeams;
After I populate my list 'allHeroes' with heroes , I want to create teams of 5 random heroes, using this method:
public Team createTeam()
{
int index=0;
Team t = new Team();
Random rnd = new Random();
int cap = allHeroes.Count;
while (t.count() < 5)
{
index = rnd.Next(0, cap);
t.Add(allHeroes.ElementAt(index));
}
return t;
}
This creates a perfect team , but if i want to create more teams, it will generate the same team over and over again.
I also have a method
public List<HeroStats> print()
{
StringBuilder sb = new StringBuilder();
List<HeroStats> l = new List<HeroStats>();
foreach (HeroStats h in team)
{
sb.AppendLine(h.HeroName);
l.Add(h);
}
Console.WriteLine(sb.ToString());
return l;
}
Which should print out the name of the heroes in a team.
Why am I getting the same team if I generate many ?
To create multiple teams I use :
Team a = new Team();
for (int i = 0; i < 2000; i++)
{
a = createTeam();
allTeams.Add(a);
}