0

How would this be done in javasript?

int guessNumber() { srand(static_cast<unsigned int>(time(0))); guess = lowGuess + (rand() % (highGuess - lowGuess)); cout<<guess<<endl; guesses += 1; return 0; }

4th Nov 2016, 7:34 PM
Christopher Farish
Christopher Farish - avatar
2 Antworten
+ 1
//Randomly generate a whole number between two values var min = 1; var max = 10; var randomInt = Math.floor(Math.random() * max) + min; alert(randomInt); This code will generate a random whole number in javascript between the min and max values. To generate another number, just pass the exact same algorithm under a different variable (or redefine the same variable). To adjust the bounds, simply change the min and max values.
4th Nov 2016, 7:59 PM
Lux
Lux - avatar
0
It is a random number generator between 2 numbers, the upper and lower bounds change every turn.
4th Nov 2016, 7:36 PM
Christopher Farish
Christopher Farish - avatar