• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Random Int between x and y
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Random Int between x and y


  • Subject: Random Int between x and y
  • From: Tom Jones <email@hidden>
  • Date: Wed, 10 Mar 2004 07:47:31 -0800

Not to pick nits, but the code below would generate a random number between 10 and 24.
Line
		int rn = (int) ((Math.random() * (m2-m1)) + m1);
Should be
		int rn = (int) ((Math.random() * (m2-m1+1)) + m1);

because there are 16 numbers between 10 and 25 inclusive.

Tom

on Wed, 10 Mar 2004 09:47:32 Michael Engelhart <email@hidden> wrote :
>>To be more specific:
>>
>>public class Test {
>>	public static void main(String args[]) {
>>		int m1 = 10;
>>		int m2 = 25;
>>		int rn = (int) ((Math.random() * (m2-m1)) + m1);
>>		System.out.println(rn);
>>	}
>>}
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: Re: How to get HttpServletRequest and HttpServletResponse?
  • Next by Date: Re: Random Int between x and y
  • Previous by thread: Re: Grrr! awakeFromInsertion - discovery
  • Next by thread: Re: Whats the recommended way for cross-object information inquiry?
  • Index(es):
    • Date
    • Thread