package pl.aswiatek.numbersteacher.businesslogic.numbergenerator.algorithm

import pl.aswiatek.numbersteacher.businesslogic.Settings
import java.util.*

class AnyNumberGenerator(
    private val random: Random,
    private val settings: Settings)
    : NumberGeneratorAlgorithm {

    override fun generate(previousNumber: Int): Int {
        var generatedNumber: Int

        do {
            generatedNumber = random.nextInt(settings.maxValue)
        } while (isInvalid(generatedNumber, previousNumber, settings.questionRadix))

        return generatedNumber
    }

    private fun isInvalid(generatedNumber: Int, previousNumber: Int, radix: Int) =
        generatedNumber == previousNumber || generatedNumber < radix
}