namespace SRandom {
    class Randomizer {
        field _activeSeed;

        constructor(seed) {
            seed = 'salted-seed:' + seed;
            hash = 2;
            for (c : seed) {
                hash = (hash * 37 + Core.ord(c)) & 0x7fffffff;
            }
            this._activeSeed = [hash];
        }

        function getInteger(min = null, max = null) {
            if (min == null) return $lib_srandom_getInteger(this._activeSeed);
            if (max == null) return $lib_srandom_getInteger(this._activeSeed) % min;
            return ($lib_srandom_getInteger(this._activeSeed) % (max - min)) + min;
        }

        function getBoolean() {
            return $lib_srandom_getBoolean(this._activeSeed);
        }

        function getFloat() {
            return $lib_srandom_getFloat(this._activeSeed);
        }

        function shuffle(list) {
            length = list.length;
            for (i = 0; i < length; ++i) {
                index = $lib_srandom_getInteger(this._activeSeed) % length;
                if (i != index) {
                    t = list[i];
                    list[i] = list[index];
                    list[index] = t;
                }
            }
        }

        function choice(list) {
            return list[$lib_srandom_getInteger(this._activeSeed) % list.length];
        }
    }
}
