• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Use of Math.random

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the use of Math.random in the following and also in general :
int x=(int)(Math.random() * 5)
Can anyone explain.
Thanks
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out
Marilyn
[This message has been edited by Marilyn deQueiroz (edited September 26, 2000).]
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
close Marilyn, you left out the text. Clickey the edit icon and see how I did it.


[This message has been edited by Apu Nahasapeemapetilon (edited September 28, 2000).]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Math.random() //generates a random number.
Math.random * 5;//multiplies it by five
(int)Math.random * 5;
//does type conversion to int, incase it may be of float type
int y = (int)Math.random * 5
// stores the value to y
if i am not mistaken Math.random generates random numbers between the range of 0 to 1. (but just check up on that again)
cheers
ak.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is correct. Math.random() generates a random number from 0 to 1 with equal probability each time (uniform distribution).
[This message has been edited by Brien Hackney (edited October 12, 2000).]
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic