Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Need Help With Random Number Generation Between Upper and Lower Bound

Reply
Thread Tools

Need Help With Random Number Generation Between Upper and Lower Bound

 
 
ANM
Guest
Posts: n/a
 
      03-06-2004
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.
 
Reply With Quote
 
 
 
 
Christophe Vanfleteren
Guest
Posts: n/a
 
      03-06-2004
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/...ml#nextInt(int)

--
Kind regards,
Christophe Vanfleteren
 
Reply With Quote
 
 
 
 
Thomas Schodt
Guest
Posts: n/a
 
      03-07-2004
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Emacs, VHDL Mode - Upper Case Enum Values & Upper Case Constants (not working)? BlackHelicopter VHDL 0 01-31-2013 04:12 AM
Lower bound & Upper bound sunil panda Java 9 10-07-2008 08:32 PM
help with upper and lower case conversion B Williams C++ 9 12-19-2006 02:58 PM
Getting lower-bound and upper-bound of strings input Rhiner Dan C++ 1 03-27-2005 02:03 AM
Regexp help - upper to lower ONLY matching this pattern Patrick Perl Misc 4 08-27-2003 06:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57