public int nextInt(int n) {
        // calcualte next element in series 
        s.add(s.get(counter + 3).multiply(new BigInteger("22695477")).add(new BigInteger("1")));
        // calculate series x from element i in s
        //BigInteger result = (s.get(counter+4).divide(new BigInteger("65536"))) .mod(new BigInteger(Integer.toString(n-1)));
        BigInteger result = (s.get(counter + 4).divide(new BigInteger("65536"))).mod(new BigInteger("16384"));
        // increment counter on every call of nextInt
        counter++;
        // convert BigInteger to int and return
        return result.intValue() % n;

    }