guneysus
4/26/2016 - 8:14 AM

Javascript deadly simple Fake date generators

Javascript deadly simple Fake date generators

var Fake = {
    boolean: function (args) {
        /**
         * http://jsfiddle.net/Ronny/Ud5vT/
         */
        
         return Math.random() < .5; // Readable, succint
    },
    
    date: function (args) {
        /**
         * 
         * http://stackoverflow.com/a/9035732/1766716 
         * */
        return new Date(args.start.getTime() + Math.random() * (args.end.getTime() - args.start.getTime()));        
    },
    
    float:function (args) {
        /**
         * 
         * USAGE
         * Fake.float({max:10, min:3});
         * 
         */
        var val = args.min + Math.random() * (args.max - args.min);
        return val;        
    },
    
    int: function (args) {
        /*
         * USAGE
         * Fake.({max:10, min:3});
         * 
         */
        return Fake.float(args) | 0;
    }
}