Math.random() *100 verses Math.random(100) [closed]










-4














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!










share|improve this question













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
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 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










  • 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() 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
















-4














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!










share|improve this question













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
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 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










  • 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() 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














-4












-4








-4







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!










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
If this question can be reworded to fit the rules in the help center, please edit the question.




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
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 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










  • 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() 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













  • 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










  • 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() 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








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













1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer



























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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.






    share|improve this answer

























      0














      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.






      share|improve this answer























        0












        0








        0






        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 '18 at 21:12









        Makoto

        80.7k15125173




        80.7k15125173













            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto