const http = require('http') const count = Number(process.argv[2]) // Seed the generator with the current time (in milliseconds) const seedRequest = http.request('http://localhost/seed', {method: 'POST'}, _ => { // Then obtain `count` random numbers getNumbers() }) seedRequest.write(JSON.stringify({seed: Date.now()})) seedRequest.end() function getNumbers() { for (let i = 0; i < count; i++) { http.get('http://localhost/next', res => { let body = '' res.setEncoding('utf8') .on('data', chunk => { // Concatenate response body into a single string body += chunk }) .on('end', () => { // Parse the JSON response and print the number console.log(JSON.parse(body).value) }) }) } }