private void CreateCards(IEnumerable <Note> notes, IDatabase db) { // Generate cards foreach (Note note in notes) { int cardsLeft = CardGenerator.Left(); double lowerCardPerNoteRatio = Math.Floor(cardsLeft / (double)NoteCount); double upperCardPerNoteRatio = Math.Ceiling(cardsLeft / (double)NoteCount); int upperMinCardRange = upperCardPerNoteRatio >= MaxCardPerNote ? MaxCardPerNote : (NoteCount == 1 ? cardsLeft : 1); int minCards = Math.Min(cardsLeft, upperMinCardRange); int maxCards = 1 + Math.Min(lowerCardPerNoteRatio <= 1 ? 1 : MaxCardPerNote, cardsLeft); int cardCount = Random.Next(minCards, maxCards); for (int i = 0; i < cardCount; i++) { Card card = CardGenerator.Generate(note.Id); note.Cards.Add(card); db?.Insert(card); } NoteCount--; } }
// // Constructor /// <summary> /// Initializes a new instance of the <see cref="CollectionGenerator" /> class. /// </summary> /// <param name="cardGenerator">Parametrized card generator.</param> /// <param name="noteCount">Note count to generate.</param> /// <param name="maxCardPerNote">Maximum number of card per note.</param> public CollectionGenerator(CardGenerator cardGenerator, int noteCount, int maxCardPerNote) { CardGenerator = cardGenerator; TimeGenerator = CardGenerator.TimeGenerator; NotesIds = new HashSet <int>(); NoteCount = noteCount; MaxCardPerNote = maxCardPerNote; }