generateFindKeys function
- FindKeyStep step,
- Random rng
As kFindKeysPerRound notas de uma rodada de step, sorteadas com rng,
sem a mesma tecla duas vezes seguidas (C#4 e Db4 são a mesma tecla). A
mesma semente dá as mesmas notas.
Implementation
List<Pitch> generateFindKeys(FindKeyStep step, Random rng) {
final pool = [for (final name in step.pool) Pitch.parse(name)];
final out = <Pitch>[];
for (var i = 0; i < kFindKeysPerRound; i++) {
var next = pool[rng.nextInt(pool.length)];
for (
var tries = 0;
out.isNotEmpty && next.midi == out.last.midi && tries < 50;
tries++
) {
next = pool[rng.nextInt(pool.length)];
}
out.add(next);
}
return out;
}