Skip to content

Instantly share code, notes, and snippets.

@RubenNL
Created November 18, 2021 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RubenNL/0083c4bea7978a2d49b9087b3b0f5340 to your computer and use it in GitHub Desktop.
Save RubenNL/0083c4bea7978a2d49b9087b3b0f5340 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
namespace GUI
{
public class Bag
{
private readonly Random _random;
private Queue<Matrix> _bag = new(); //using queue for easy pop/dequeue.
public Bag(int seed)
{
_random = new Random(seed);
}
private void Fill()
{
_bag = new Queue<Matrix>(Matrix.GetMatrixes().OrderBy(_ => _random.Next()));
}
public Matrix GetNextMatrix()
{
if (_bag.Count == 0) Fill();
return _bag.Dequeue();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment