package randomizer

import (
	"fmt"
	"math/rand"
)

type Random interface {
	Int() int
}

func init() {}

type rndGenerator func(n int) int

type Randomizer struct {
	fn rndGenerator
}

func NewRandomizer(fn rndGenerator) *Randomizer {
	return &Randomizer{fn: fn}
}

func (r *Randomizer) Int(n int) int {
	return r.fn(n)
}

func Rand(rand int) int {
	return randGen(rand)
}
func realRand(n int) int { return int(rand.Intn(n)) }
func fakeRand(n int) func(numb int) int {
	return func(numb int) int {
		if n >= numb {
			panic(fmt.Sprintf("%d Should not be superior of %d", n, numb))
		}
		return n
	}
}

var randGen = NewRandomizer(realRand).Int

func FakeRandomizer(n int) {
	randGen = NewRandomizer(fakeRand(n)).Int
}
