Skip to content

Commit

Permalink
Bug fix: CannotDivideByZeroException.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlnalber committed Aug 30, 2021
1 parent 7d05320 commit f7c91ae
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions GAS/Course.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public static Period GetRandomPeriod(Course forCourse)
{
//Erstelle eine zufällige Stunde:
Random random = new();
Period period = new Random().Choices((from p in GetAllPeriods() select (p, 1.0 / forCourse.IssuesWith(p))).ToArray()).Item1;
Period period = new Random().Choices((from p in GetAllPeriods() select (p, 1.0 / (forCourse.IssuesWith(p) + 1.0))).ToArray()).Item1;
Period bestPeriod = period;

//Gehe solange durch, bis eine passende Stunde gefunden wurde.
Expand Down Expand Up @@ -390,7 +390,14 @@ public static Period GetRandomPeriod(Course forCourse, Course fromCourse)
{
//Suche eine zufällige Stunde aus.
Random random = new();
int index = random.Next(fromCourse.Periods.Length);
IEnumerable<(int, double)> periodsEnumerable()
{
for (int i = 0; i < fromCourse.Periods.Length; i++)
{
yield return (i, 1.0 / (forCourse.IssuesWith(fromCourse.Periods[i]) + 1.0));
}
}
int index = new Random().Choices(periodsEnumerable().ToArray()).Item1;
Period bestPeriod = fromCourse.Periods[index];

//Gehe solange durch, bis eine passende Stunde gefunden wurde.
Expand Down

0 comments on commit f7c91ae

Please sign in to comment.