|
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-
bounces@xxxxxxxxxxxx] On Behalf Of Adam Glauser
Sent: Tuesday, February 12, 2008 1:59 PM
To: midrange-l@xxxxxxxxxxxx
Subject: Re: SQL RAND function question
Wilt, Charles wrote:
I'm thinking perhaps the way I'm going from the RAND() results to ainteger from 0-11 is the problem.
Anybody understand what I'm doing wrong?months
myDate = date('2008-03-01') + cast(round((rand(12) * 11),0) as int)
I don't think round() is what you want, although I'm confused a bit by
the distribution of results that you stated. Anyway, here is why I
think that you got about half as many 11s as you expected:
rand(12) * 11 gives a double float number r, in the range [0,11].
round(r) gives an integer in the set Z' (0,1,2,...,11).
What values result in each number in the set Z'?
if r is in [0,0.5), r' = 0
if r is in [0.5,1.5), r' = 1
if r is in [1.5,2.5), r' = 2
...
if r is in [9.5 ,10.5), r' = 10
if r is in [10.5,11] , r' = 11
So, there are only half as many values that will lead to a result of
either 0 or 11 as there are that lead to any of the other numbers.
Of course, the problem with this conclusion is that it doesn't explain
why you got half as many 1s as you were expecting.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.