U4L5 5B AV Cars

To get numbers between 200 and 500 inclusive don’t you have to multiply by 301 rather than 300 as 300 will only generate up to 299 so the highest value you could generate is 499

1 Like

Here’s the format for Java specifically, but probably similar in other languages:

(int)(Math.random() * range) + min

If you want 200 - 500, it would be (int)(Math.rand()*301) + 200

That would get you 200-500.

1 Like

@bbinkley and @dherbert you are both correct. I see that @bbinkley found that the answer key for Level 5 choice B is wrong. I went ahead and clicked the “Rate this Lesson” button in the unit landing page and submitted what @dherbert said:
“The exemplar solution for Level 5 choice B is incorrect.
If you want 200 - 500, it would be (int)(Math.rand()*301) + 200
That would get you 200-500.”

If you both wouldn’t mind also doing this I think that if more people review the same lesson it gets put at a higher priority.

-Best
Sam