Re: Random integer formula?
From: Top Spin (ToppSpin_at_hotmail.com)
Date: 12/03/04
- Next message: Jim Carlock: "Re: Inline assembly [MULTIPOST]"
- Previous message: jf: "Re: UTF8 to Unicode Visual Basic"
- In reply to: Jim Mack: "Re: Random integer formula?"
- Next in thread: Bonj: "Re: Random integer formula?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 02 Dec 2004 22:29:30 -0800
On Thu, 2 Dec 2004 19:41:35 -0500, "Jim Mack" <jmack@mdxi.nospam.com>
wrote:
>Top Spin wrote:
>> On Wed, 1 Dec 2004 06:28:13 -0500, "Jim Mack" <jmack@mdxi.nospam.com>
>> wrote:
>>
>>
>> I ran it from the Immediate window using
>>
>> MinMaxDist 3,5
>>
>> The MsgBox popped up saying that INext was "6".
>>
>> I have since rewritten the function to save the random number in a
>> separate variable and added a berak if it happens again, but it
>> hasn't.
>>
>> The statement
>>
>> lNext = Int((Rnd() * (iMax - iMin + 1)) + iMin)
>>
>> should never return a value outside (iMin,iMax), right?
>
>More than "shouldn't", I believe that it "cannot", although I would have
>cast this somewhat differently:
>
>Int(Rnd * (iMax - iMin + 1)) + iMin
>
>Note that here, iMin is not part of what is seen by Int(). I don't think
>it makes any difference, I just would never do it.
It does make one difference: it permits the domain to include negative
numbers without having to worry about whether to use Int() or Fix(). I
think it is a cleaner formula.
>I wish that for testing you had broken the parts out so that at the
>point you got the trap you could see exactly what Rnd() had produced,
>because that's the only interesting part.
Me, too. I usually don't write long statements for just that reason
when developing. I may later combine them, but I usually break them
out so I can see intermediate results.
I have runs long tests since and no traps. I'm guessing it was a
coding error on my part.
-- Running MS VB 6.0 Pro (SP5) PC: HP Omnibook 6000 OS: Win 2K SP-4 (5.00.2195) Email: Usenet-20031220 at spamex.com (11/03/04)
- Next message: Jim Carlock: "Re: Inline assembly [MULTIPOST]"
- Previous message: jf: "Re: UTF8 to Unicode Visual Basic"
- In reply to: Jim Mack: "Re: Random integer formula?"
- Next in thread: Bonj: "Re: Random integer formula?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|