var op = boot.opath;
var randgen = boot.rand;
var zlib = boot.zlib;
Buffer = boot.Buffer;

var nd= new Date();

var seed = [nd.getFullYear(), "-" ,(nd.getMonth() + 1) , "-" , (nd.getDate()) , " " , (nd.getTime())].join("");
console.log(seed);
seed = "2018-01-01"
console.log(seed);

var rand = randgen.create(seed);


var usersrand = randgen.create("users.iske.dk");


var a = {}

function aa(a) {

    var x = 5000; //rand.range(30);
    for (var i = 0; i < x; i++) {

        var tt = get_random_name();
        a["u" + i] = bb(tt);

    }
    return a;
}

function bb(a) {
    var x = rand.range(10);
    for (var i = 0; i < x; i++) {
        var nam = "f_" + rand.range(1000000);


        a[nam] = get_random_name().t.substring(0, 8);
    }

    return a;
}
/*
function cc(a){
	var x = rand.range(4);
	for(var i =0;i<x;i++){
		var nam= "f_"+rand.range(1000000);
		a[nam] = {aa: rand.range(1000000), bac: dd({name: get_random_name()}) };
	}
	return a;
}
function dd(a){
	var x = rand.range(4);
	for(var i =0;i<x;i++){
		var nam= "f_"+rand.range(1000000);
		a[nam] = {aa: rand.range(1000000) };
	}
	return a;
}
*/

function get_clean_name(len) {


    var t = rand.string(len * 2);

    var tb = t.replace(/[^a-zA-Z0-9]*/g, "");

    return tb.substring(0, len);
}


function get_random_name() {

    var t = rand.string(256);


    var ta = t.replace(/[^aeiyuo]*/g, "");
    var taa = t.replace(/[^qrtpsdfghjklzxcvbnm]*/g, "");
    var tb = t.replace(/[^A-Z]*/g, "");
    //	   var	tc = t.replace(/[^0-9]*/g,"");
    //	   var	td = t.replace(/[a-zA-Z0-9]*/g,"");

    var fname = tb[0] + (findUnique(ta).split("")).slice(0, 4).join("") + findUnique(taa.substring(0, 1))
    var lname = tb[1] + "" + (findUnique(ta).split("")).reverse().slice(0, 2).join("") + (findUnique(taa).split("")).reverse()
        .slice(1, 2).join("") + (findUnique(ta).split("")).slice(0, 2).join("");

    var mname = tb[2] + "" + (findUnique(ta).split("")).reverse().slice(0, 2).join("") + (findUnique(taa).split("")).slice(
        1, 2).join("");

    return {
        f: fname,
        m: mname,
        l: lname,
        t: tb
    };

}

function findUnique(str) {
    var i, ch;
    var len = str.length;
    var freqMap = new Map();
    var uniq = '';

    for (i = 0; i < len; i++) {
        ch = str[i];
        if (!freqMap.get(ch)) {
            freqMap.set(ch, 1);
        } else {
            freqMap.set(ch, -1);
        }
    }

    freqMap.forEach(function(val, key) {
        //	console.log(val,key);
        // if (val == 1) {
        uniq += key;
        // }
    });

    return uniq;
}


//var ff = aa({});

//var s = JSON.stringify(ff);

var rr = {
    "test": 1
}

op.set(rr, get_clean_name(rand.range(100)), rand.range(10000000))
op.set(rr, get_clean_name(rand.range(100)), rand.range(10000000))
op.set(rr, get_clean_name(rand.range(100)), rand.range(10000000))
op.set(rr, get_clean_name(rand.range(100)), rand.range(10000000))
op.set(rr, get_clean_name(rand.range(100)), rand.range(10000000))
op.set(rr, get_clean_name(rand.range(100)), rand.range(10000000))
op.set(rr, get_clean_name(rand.range(100)), rand.range(10000000))
op.set(rr, get_clean_name(rand.range(100)), rand.range(10000000))
op.set(rr, get_clean_name(rand.range(100)), rand.range(10000000))
op.set(rr, get_clean_name(rand.range(100)), rand.range(10000000))


console.log(op.flatten(rr));



function gframe() {




}






function ned() {

    var input = s;

    var deflated = zlib.deflateSync(input).toString('base64');
    var inflated = zlib.inflateSync(new Buffer(deflated, 'base64')).toString();



    var dd = zlib.deflateSync(ss).toString('base64');
    var ii = zlib.inflateSync(new Buffer(dd, 'base64')).toString();

    console.log(ffa.length, s.length, ss.length, dd.length, ii.length / dd.length);

    console.log(ffa.slice(0, 10), ffa.pop());

}