posted 3 years ago

I having a bit of trouble understanding how this works

Math.random();

I know its going to spit out a number between 0 and 1 but I dont know why its in that range if there are no numbers there.

The second part I'm having trouble understanding is how to adjust it for example make it between 1 and 100

Math.random();

I know its going to spit out a number between 0 and 1 but I dont know why its in that range if there are no numbers there.

The second part I'm having trouble understanding is how to adjust it for example make it between 1 and 100

posted 3 years ago

There are an infinite amount of numbers there. The method does not return an integer.

Think about it for a minute. You have a number between 0.0 and 1.00 (non-inclusive). How could you convert that to a larger number?

Davey Lopez wrote:I know its going to spit out a number between 0 and 1 but I dont know why its in that range if there are no numbers there.

There are an infinite amount of numbers there. The method does not return an integer.

The second part I'm having trouble understanding is how to adjust it for example make it between 1 and 100

Think about it for a minute. You have a number between 0.0 and 1.00 (non-inclusive). How could you convert that to a larger number?

Davey Lopez

Ranch Hand

Posts: 33

posted 3 years ago

Well, that is not true if we talk about Java and

You might want to convert a number in range 0.0-1.0 to an integer but you may also get this integer directly by using

Bear Bibeault wrote:There are an infinite amount of numbers there.

Well, that is not true if we talk about Java and

`double`type. I just wanted to clarify this.

You might want to convert a number in range 0.0-1.0 to an integer but you may also get this integer directly by using

`java.util.Random`class and its

`nextInt(int n)`

`method`.