Math.random help! please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kaka123
    New Member
    • Dec 2007
    • 8

    Math.random help! please

    hey im new to java and im trying to get stars to appear randomly accross the sky and i cant fugure out how to use the functions
    for (a=1;a<1000;a=a +10)
    {
    g.fillOval(0+a, 2,6,6);


    }
    thats what i have now and the stars go stright accross teh sky..if nothing else then i would just line the stars up in teh sky but no matter how big i make my for loop, the starts just go one line stright accross the top...
    id like stars(ovals) from 0,350
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by kaka123
    hey im new to java and im trying to get stars to appear randomly accross the sky and i cant fugure out how to use the functions
    for (a=1;a<1000;a=a +10)
    {
    g.fillOval(0+a, 2,6,6);


    }
    thats what i have now and the stars go stright accross teh sky..if nothing else then i would just line the stars up in teh sky but no matter how big i make my for loop, the starts just go one line stright accross the top...
    id like stars(ovals) from 0,350
    Well, you haven't used Math.random in your loop at all so you shouldn't really expect to get random output.

    Comment

    • kaka123
      New Member
      • Dec 2007
      • 8

      #3
      yea i know im sorry...i was just showing you my loop with the stars goin accros the sky..i didnt use math.random beacuse i dont know how to use it..thus me asking the question

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by kaka123
        yea i know im sorry...i was just showing you my loop with the stars goin accros the sky..i didnt use math.random beacuse i dont know how to use it..thus me asking the question
        A good source of information about Java classes and their methods is the API specs. See the entry for Math.random here.
        Also have a look at the specs for the java.util.Rando m class

        Comment

        Working...