Generate A Random Whole Number Solution

I understand the problem, and I can get the correct solution. It just seems extremely limiting to have the only solution be multiply the random number generated by 10 instead of allowing other solutions such as using a modulo. I don’t suppose there would be any way to update the tests to allow for other solutions? I just thought I’d ask.

Perhaps I’m missing something, but I don’t see how a modulus operator would be useful for that problem.

you can simply take the floor of the multiplied randomly generated number by anything larger than 10 and then taking the modulo of 10 will return a value between 0 and 9. It accomplishes the same goal as the random whole number between 0 and 9 inclusive.

for example.
Math.floor(Math.random() * 20) % 10;

it will always return a number between 0 and 9.

I’m still missing the point of using the modulus operator.

It is super easy to do this wrong and bias the pseudorandom number. This is a statistical minefield.

It’s simply a matter of being allowed to use another solution instead of being forced to multiply the random number by 10.

The modulus operator in this context was just an example. If it returns a random number between 0 and 9, it should be allowed.

Ah, no. The requirement is not ‘return a number between 0 and 9’. The requirement is to return a pseudorandom number between 0 and 9. There are lots of ways to write statistical bias into your function, and it’s hard to test if this has been done.

This lesson is about learning and using the generally accepted way to convert a pseudorandom number from 0 to 1 into a pseudorandom number from 0 to num and take only the integer part.

Ah, I see. I misunderstood the purpose of the exercise. Thanks for the help/explanation :slight_smile: