Results 1 to 3 of 3
  1. #1
    oridov is offline Member
    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0

    Default Generating a random number

    Hi all,
    Can someone please explain to me how can I generate a random (double) number from 0 to 1, including 1?

    I used this, but it excludes 1:

    double RandomValue;
    RandomValue = Math.random();


    Thanks!

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Try this...

    Try this... Random class:
    Random (Java Platform SE 6)
    and specailly this method:
    Random.nextInt(int n) (Java Platform SE 6))

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Just got another idea...

    You can also take a certain level and turn into a 1. For example:

    Java Code:
    if (n == 0.99)
     {
      n=1;
     }
    or
    Java Code:
    if (n > 0.95)
     {
       n=1;
     }
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Random number help
    By jgonzalez14 in forum New To Java
    Replies: 5
    Last Post: 09-16-2008, 09:13 AM
  2. trying to add up random numbers into one number
    By pjr5043 in forum New To Java
    Replies: 4
    Last Post: 09-15-2008, 02:20 PM
  3. Random number
    By jithan in forum Advanced Java
    Replies: 1
    Last Post: 06-13-2008, 01:42 PM
  4. Generating number sequences
    By hawkmauk in forum New To Java
    Replies: 0
    Last Post: 11-15-2007, 03:32 PM
  5. generating random numbers in a 5x5 array.
    By acidacid in forum New To Java
    Replies: 3
    Last Post: 08-14-2007, 03:44 AM

Posting Permissions

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