Created
September 3, 2019 02:19
-
-
Save zhangolve/ca5a6731b418f4c5a11c536cc8e52819 to your computer and use it in GitHub Desktop.
get random number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import { isNumber } from "util"; | |
const readline = require('readline'); | |
// input | |
function random(x,y) { | |
if(!x || !y) { | |
console.log('please input INT numbers !!'); | |
} else if ( (x-y)>0){ | |
console.log('x must smaller or equal with y') | |
}else { | |
return Math.random() * (y-x) + x; | |
} | |
} | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
rl.question( 'input two int numbers, split using ,', (answer) => { | |
// TODO: Log the answer in a database | |
const numbers= answer.split(',').map(x=>parseInt(x)); | |
console.log(numbers) | |
const randomNumber = Math.round(random(numbers[0], numbers[1])); | |
console.log(randomNumber) | |
rl.close(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment