I have a class that creates a list of numbers that count down from 100 to 0 (decremented by random values).
My aim is to apply this method to an instance of a class (where the list is one of the parameters). However, I don't believe it's working as expected and I also don't believe it's the most effective way of doing this. I'm fairly new to c#/coding so any advice would be great! Here is my code:
public class Emotion
{
readonly string name;
readonly List<int> statusChange;
public Emotion(string name, List<int> statusChange)
{
this.name = name;
this.statusChange = statusChange;
}
static void Main(string[] args)
{
numberGenerator();
Emotion Hunger = new Emotion("Hunger", numberGenerator());
}
static List<int> numberGenerator()
{
List<int> numberGen = new List<int>();
numberGen.Add(100);
Random r = new Random();
while (numberGen.Last() != 0)
{
int lastInt = numberGen.Last();
int rInt = r.Next(1, 15); //might change the range
int newValue = lastInt - rInt;
numberGen.Add(newValue);
}
//prints out list as a string
Console.WriteLine(String.Join(",", numberGen));
return numberGen;
}
}
(I'm aware that some c# conventions may also be wrong in my code! I will fix it after I resolve this issue)