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; }
2 odpowiedzi
+ 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.
0
It is a random number generator between 2 numbers, the upper and lower bounds change every turn.