Results 1 to 3 of 3

Thread: Random Number

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Thumbs up

    Does anybody know how to make a random number thats not between 1 - 0?
    Im traying to make a simple game to teach myself, and im traying to generate a random number from 1 - 11.

    Thanks!
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    Once you have a random number that is between 0-1 you multiply it by 11, round down, and add one.:

    double tempValue = Math.random() * maxValue;
    int value = (int) Math.floor(tempValue) + 1;

    Thats acually a bit more code then you need.
    "People who think they know everything are a great annoyance to those of us who do."

  3. #3

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Talking

    Works great, thanks!
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width