Math.random() *100 verses Math.random(100) [closed]
I'm new to java and I stumbled on the Math class. I was wondering if there was a difference between Math.random() *100 verses Math.random(100)? Would both outputs be a number between 0-99 or would Math.random(100) output a number between 0-100?
Thank you!
java
closed as off-topic by Larry Shatzer, Progman, NathanOliver, Aomine, Paul Roub Nov 26 '18 at 22:39
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Larry Shatzer, Progman, NathanOliver, Aomine, Paul Roub
add a comment |
I'm new to java and I stumbled on the Math class. I was wondering if there was a difference between Math.random() *100 verses Math.random(100)? Would both outputs be a number between 0-99 or would Math.random(100) output a number between 0-100?
Thank you!
java
closed as off-topic by Larry Shatzer, Progman, NathanOliver, Aomine, Paul Roub Nov 26 '18 at 22:39
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Larry Shatzer, Progman, NathanOliver, Aomine, Paul Roub
5
There is no method inMath
calledrandom
that takes any parameters; there is only the one that takes no parameters.
– rgettman
Nov 12 '18 at 21:10
you should carefully take a look to the doc....
– ΦXocę 웃 Пepeúpa ツ
Nov 12 '18 at 21:11
1
Definitely recommend trying to run code as a first step
– Ben Jones
Nov 12 '18 at 21:11
What do the docs forMath.random()
vsMath.random(100)
say (hint one doesn't exist)? Do the docs say the random number max is inclusive (0-99) or exclusive (0-100)? If I remember correctlyMath.random()
returns a random float from 0 to 1. Does multiplying every possible float from 0 to 1 result in a number between 0 and 100?
– MeetTitan
Nov 12 '18 at 21:13
add a comment |
I'm new to java and I stumbled on the Math class. I was wondering if there was a difference between Math.random() *100 verses Math.random(100)? Would both outputs be a number between 0-99 or would Math.random(100) output a number between 0-100?
Thank you!
java
I'm new to java and I stumbled on the Math class. I was wondering if there was a difference between Math.random() *100 verses Math.random(100)? Would both outputs be a number between 0-99 or would Math.random(100) output a number between 0-100?
Thank you!
java
java
asked Nov 12 '18 at 21:08
John Doe
32
32
closed as off-topic by Larry Shatzer, Progman, NathanOliver, Aomine, Paul Roub Nov 26 '18 at 22:39
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Larry Shatzer, Progman, NathanOliver, Aomine, Paul Roub
closed as off-topic by Larry Shatzer, Progman, NathanOliver, Aomine, Paul Roub Nov 26 '18 at 22:39
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Larry Shatzer, Progman, NathanOliver, Aomine, Paul Roub
5
There is no method inMath
calledrandom
that takes any parameters; there is only the one that takes no parameters.
– rgettman
Nov 12 '18 at 21:10
you should carefully take a look to the doc....
– ΦXocę 웃 Пepeúpa ツ
Nov 12 '18 at 21:11
1
Definitely recommend trying to run code as a first step
– Ben Jones
Nov 12 '18 at 21:11
What do the docs forMath.random()
vsMath.random(100)
say (hint one doesn't exist)? Do the docs say the random number max is inclusive (0-99) or exclusive (0-100)? If I remember correctlyMath.random()
returns a random float from 0 to 1. Does multiplying every possible float from 0 to 1 result in a number between 0 and 100?
– MeetTitan
Nov 12 '18 at 21:13
add a comment |
5
There is no method inMath
calledrandom
that takes any parameters; there is only the one that takes no parameters.
– rgettman
Nov 12 '18 at 21:10
you should carefully take a look to the doc....
– ΦXocę 웃 Пepeúpa ツ
Nov 12 '18 at 21:11
1
Definitely recommend trying to run code as a first step
– Ben Jones
Nov 12 '18 at 21:11
What do the docs forMath.random()
vsMath.random(100)
say (hint one doesn't exist)? Do the docs say the random number max is inclusive (0-99) or exclusive (0-100)? If I remember correctlyMath.random()
returns a random float from 0 to 1. Does multiplying every possible float from 0 to 1 result in a number between 0 and 100?
– MeetTitan
Nov 12 '18 at 21:13
5
5
There is no method in
Math
called random
that takes any parameters; there is only the one that takes no parameters.– rgettman
Nov 12 '18 at 21:10
There is no method in
Math
called random
that takes any parameters; there is only the one that takes no parameters.– rgettman
Nov 12 '18 at 21:10
you should carefully take a look to the doc....
– ΦXocę 웃 Пepeúpa ツ
Nov 12 '18 at 21:11
you should carefully take a look to the doc....
– ΦXocę 웃 Пepeúpa ツ
Nov 12 '18 at 21:11
1
1
Definitely recommend trying to run code as a first step
– Ben Jones
Nov 12 '18 at 21:11
Definitely recommend trying to run code as a first step
– Ben Jones
Nov 12 '18 at 21:11
What do the docs for
Math.random()
vs Math.random(100)
say (hint one doesn't exist)? Do the docs say the random number max is inclusive (0-99) or exclusive (0-100)? If I remember correctly Math.random()
returns a random float from 0 to 1. Does multiplying every possible float from 0 to 1 result in a number between 0 and 100?– MeetTitan
Nov 12 '18 at 21:13
What do the docs for
Math.random()
vs Math.random(100)
say (hint one doesn't exist)? Do the docs say the random number max is inclusive (0-99) or exclusive (0-100)? If I remember correctly Math.random()
returns a random float from 0 to 1. Does multiplying every possible float from 0 to 1 result in a number between 0 and 100?– MeetTitan
Nov 12 '18 at 21:13
add a comment |
1 Answer
1
active
oldest
votes
Math.random()
exists. Math.random(int)
does not exist.
You may be getting that mixed up with the Random
class constructor, which takes a long
as a seed value, meaning your results will be pseudorandom and by consequence, repeatable.
If you wanted a number between 0 and 99 I actually would recommend that you use Random
. You can leverage random.nextInt(100)
to get a value between 0 and 99. Multiplying floats gets dicey very quickly, since Math.random()
only produces a floating-point number.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Math.random()
exists. Math.random(int)
does not exist.
You may be getting that mixed up with the Random
class constructor, which takes a long
as a seed value, meaning your results will be pseudorandom and by consequence, repeatable.
If you wanted a number between 0 and 99 I actually would recommend that you use Random
. You can leverage random.nextInt(100)
to get a value between 0 and 99. Multiplying floats gets dicey very quickly, since Math.random()
only produces a floating-point number.
add a comment |
Math.random()
exists. Math.random(int)
does not exist.
You may be getting that mixed up with the Random
class constructor, which takes a long
as a seed value, meaning your results will be pseudorandom and by consequence, repeatable.
If you wanted a number between 0 and 99 I actually would recommend that you use Random
. You can leverage random.nextInt(100)
to get a value between 0 and 99. Multiplying floats gets dicey very quickly, since Math.random()
only produces a floating-point number.
add a comment |
Math.random()
exists. Math.random(int)
does not exist.
You may be getting that mixed up with the Random
class constructor, which takes a long
as a seed value, meaning your results will be pseudorandom and by consequence, repeatable.
If you wanted a number between 0 and 99 I actually would recommend that you use Random
. You can leverage random.nextInt(100)
to get a value between 0 and 99. Multiplying floats gets dicey very quickly, since Math.random()
only produces a floating-point number.
Math.random()
exists. Math.random(int)
does not exist.
You may be getting that mixed up with the Random
class constructor, which takes a long
as a seed value, meaning your results will be pseudorandom and by consequence, repeatable.
If you wanted a number between 0 and 99 I actually would recommend that you use Random
. You can leverage random.nextInt(100)
to get a value between 0 and 99. Multiplying floats gets dicey very quickly, since Math.random()
only produces a floating-point number.
answered Nov 12 '18 at 21:12
Makoto
80.7k15125173
80.7k15125173
add a comment |
add a comment |
5
There is no method in
Math
calledrandom
that takes any parameters; there is only the one that takes no parameters.– rgettman
Nov 12 '18 at 21:10
you should carefully take a look to the doc....
– ΦXocę 웃 Пepeúpa ツ
Nov 12 '18 at 21:11
1
Definitely recommend trying to run code as a first step
– Ben Jones
Nov 12 '18 at 21:11
What do the docs for
Math.random()
vsMath.random(100)
say (hint one doesn't exist)? Do the docs say the random number max is inclusive (0-99) or exclusive (0-100)? If I remember correctlyMath.random()
returns a random float from 0 to 1. Does multiplying every possible float from 0 to 1 result in a number between 0 and 100?– MeetTitan
Nov 12 '18 at 21:13