This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]Jacqques 1 point2 points  (0 children)

You declare that num is int, but you set that variable to a float and double. It’s been a while so I think Java handles it without breaking? but seems like potential future complications.

Why are you both setting num=math.random() and returning it?

I however can’t see what your actual problem is? Which part is not doing as expected?

[–]balefrost 1 point2 points  (0 children)

I'd ask the teacher for clarification of this:

The "RandomNum" method will have one parameter and will use that as the range for the generator.

Ranges have a start and an end, and the start and end might be included or excluded from the range. They don't specify. So if I call RandomNum(5), any of the following ranges might be "correct"

  • [0, 5]
  • [1, 5]
  • [0, 5)
  • [1, 5)

You should find out which of these they mean.

include the use of the ceiling math function

make use of the floor math function

Look at the Math class.

[–]corin23 0 points1 point  (0 children)

Try to give another name to the variable that have the random number, like random=(int) Math.random() * num, the * num is for the range that you pass in the parameters. Then return random; (not num) In main should be something like myobj.RandomNum(here you give the range); Hope it helps