• 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
Re: Random Int between x and y
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Random Int between x and y


  • Subject: Re: Random Int between x and y
  • From: Michael Engelhart <email@hidden>
  • Date: Wed, 10 Mar 2004 09:47:32 -0500

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);
	}
}


Mike

On Mar 10, 2004, at 9:33 AM, email@hidden wrote:

Hi David

On 10 Mar 2004, at 13:46, David Griffith wrote:

Hi all,

Is there an easy way to generate a random int in the range x <= int <= y?
I have found a couple of methods but they don't appear to do what I need.

Use java.lang.Math.random().

If you need a cryptographically strong number, you can look at java.security.SecureRandom

Cheers,
-- Denis.

I'm sure there's a simple answer....

Regards,
Dave.
_______________________________________________
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.
_______________________________________________
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.


  • Follow-Ups:
    • Re: Random Int between x and y
      • From: Kieran Kelleher <email@hidden>
References: 
 >Random Int between x and y (From: David Griffith <email@hidden>)
 >Re: Random Int between x and y (From: email@hidden)

  • Prev by Date: Re: Random Int between x and y
  • Next by Date: Re: Grrr! awakeFromInsertion - discovery
  • Previous by thread: Re: Random Int between x and y
  • Next by thread: Re: Random Int between x and y
  • Index(es):
    • Date
    • Thread