UNPKG

601 BJavaScriptView Raw
1var crypto = require('crypto');
2process.stdout.write(
3 'Writing to stdout at random intervals...\n'
4);
5var nanoPow = Math.pow(10,9);
6var last = (new Date()).getTime();
7var times = 20;
8function randomTime() {
9 crypto.randomBytes(nanoPow/100, function(e, b) {
10 if (e) throw e;
11 last = (new Date()).getTime() - last;
12 var seconds = last / 1000;
13 process.stdout.write('above line took about ' + seconds.toFixed(4) + ' seconds\n');
14 last = (new Date()).getTime();
15 if (times--) setTimeout(randomTime, b.readUInt8(0) * 2);
16 });
17}
18randomTime();
19process.stdout.on('error', process.exit);