@@ -0,0 +1,33 @@
|
||||
using EinmaleinsTrainer.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace EinmaleinsTrainer.Services;
|
||||
|
||||
public class QuestionGenerator
|
||||
{
|
||||
private readonly Random _random = new();
|
||||
|
||||
public List<Question> Generate(List<int> rows, bool includeSquares)
|
||||
{
|
||||
var pool = new List<Question>();
|
||||
|
||||
foreach (var r in rows)
|
||||
{
|
||||
for (int i = 1; i <= 10; i++)
|
||||
pool.Add(new Question { A = r, B = i });
|
||||
}
|
||||
|
||||
if (includeSquares)
|
||||
{
|
||||
for (int i = 1; i <= 10; i++)
|
||||
pool.Add(new Question { A = i, B = i });
|
||||
}
|
||||
|
||||
return pool.OrderBy(_ => _random.Next())
|
||||
.Take(10)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user