Need Help With Random Number Generation Between Upper and Lower Bound

Discussion in 'Java' started by ANM, Mar 6, 2004.

  1. ANM

    ANM Guest

    Can someone recommend some code that I can reuse to generate random
    numbers between an upper and lower bound in a range. Essentially, I
    am looking for a function that will take in two integers as parameters
    and then compute and return a random number that lies between that
    range. Any help would be greatly appreciated. I am aware of the
    Math.random method but, want to know if there is something better for
    what I am trying to accomplish here for a school project.
    ANM, Mar 6, 2004
    #1
    1. Advertising

  2. ANM wrote:

    > Can someone recommend some code that I can reuse to generate random
    > numbers between an upper and lower bound in a range. Essentially, I
    > am looking for a function that will take in two integers as parameters
    > and then compute and return a random number that lies between that
    > range. Any help would be greatly appreciated. I am aware of the
    > Math.random method but, want to know if there is something better for
    > what I am trying to accomplish here for a school project.


    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html#nextInt(int)

    --
    Kind regards,
    Christophe Vanfleteren
    Christophe Vanfleteren, Mar 6, 2004
    #2
    1. Advertising

  3. Re: Need Help With Random Number Generation Between Upper and LowerBound

    ANM wrote:
    > /need to/ generate random
    > numbers between an upper and lower bound in a range. Essentially, I
    > am looking for a function that will take in two integers as parameters
    > and then compute and return a random number that lies between that
    > range.
    > I am aware of the Math.random method
    > but want to know if there is something better for
    > what I am trying to accomplish here for a school project.


    Your problem is conceptual.

    Try to visualize what happens if you add a fixed offset (lower bound)
    to the output of a random number generator method.

    Adjust the range you "feed" the random number generator method accordingly.
    Thomas Schodt, Mar 7, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sunil panda

    Lower bound & Upper bound

    sunil panda, Dec 25, 2003, in forum: Java
    Replies:
    9
    Views:
    7,206
    thushara wijeratna
    Oct 7, 2008
  2. Rhiner Dan
    Replies:
    1
    Views:
    737
    Mike Wahler
    Mar 27, 2005
  3. B Williams
    Replies:
    9
    Views:
    459
    Yannick Tremblay
    Dec 19, 2006
  4. Patrick
    Replies:
    4
    Views:
    173
    Markus W.
    Aug 27, 2003
  5. BlackHelicopter
    Replies:
    0
    Views:
    499
    BlackHelicopter
    Jan 31, 2013
Loading...

Share This Page