Random Int between x and y
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.