So don't add 1.


Michael Schutte
Admin Professional
Bob Evans Farms, Inc.
"The Secret's the Sauce! Enjoy our new Bob-B-Q Pulled Pork Knife & Fork
Sandwich!"


midrange-l-bounces@xxxxxxxxxxxx wrote on 02/12/2008 03:40:34 PM:

Michael,

In this case I want 0..11 not 1..12.

Charles Wilt
Software Engineer
CINTAS Corporation - IT 92B
513.701.1307

wiltc@xxxxxxxxxx


-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-
bounces@xxxxxxxxxxxx] On Behalf Of Michael_Schutte@xxxxxxxxxxxx
Sent: Tuesday, February 12, 2008 2:51 PM
To: Midrange Systems Technical Discussion
Subject: RE: SQL RAND function question

If I remember correctly.... in TI-83 calculator (I know this is going
to
make me sound real geeky!!!!), if I wanted to get a random number
between
1 and 100. I had to take the random function and multiply by 100 then
add
1. Because int(rand() * 100) resulted in 0 through
99.9999999999999999
etc... I believe that's where I was doing that calculation.

So to answer your question... shouldn't it be...

(INT(RAND() * 12) + 1) as RandonNumber


Michael Schutte
Admin Professional
Bob Evans Farms, Inc.
"The Secret's the Sauce! Enjoy our new Bob-B-Q Pulled Pork Knife & Fork
Sandwich!"

midrange-l-bounces@xxxxxxxxxxxx wrote on 02/12/2008 02:44:30 PM:

Adam,

Thanks for the explanation, that's what I was thinking, but you
spelled it out nicely.

Like you, I'm a little confused about getting half the 1's I
expected. Getting half the 0's would
have made sense.

Still I'm confused, IIRC every example I've seen about using _any_
built in random number function has
said basically, they return [0,1) or [0,1] and to get a number
between a given range multiply by the
range. (IBM's SQL manual included!)

Obviously, that doesn't hold true for the reasons you've explained.

So what is the "right" answer to using such a built in random number
function?

Charles Wilt
Software Engineer
CINTAS Corporation - IT 92B
513.701.1307
wiltc@xxxxxxxxxx


-----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
a
integer from 0-11 is the problem.
Anybody understand what I'm doing wrong?

myDate = date('2008-03-01') + cast(round((rand(12) * 11),0) as
int)
months

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.




This e-mail transmission contains information that is intended to be
confidential and privileged. If you receive this e-mail and you are
not a named addressee you are hereby notified that you are not
authorized to read, print, retain, copy or disseminate this
communication without the consent of the sender and that doing so is
prohibited and may be unlawful. Please reply to the message
immediately by informing the sender that the message was
misdirected. After replying, please delete and otherwise erase it
and any attachments from your computer system. Your assistance in
correcting this error is appreciated.
--
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.


--
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.




This e-mail transmission contains information that is intended to be
confidential and privileged. If you receive this e-mail and you are
not a named addressee you are hereby notified that you are not
authorized to read, print, retain, copy or disseminate this
communication without the consent of the sender and that doing so is
prohibited and may be unlawful. Please reply to the message
immediately by informing the sender that the message was
misdirected. After replying, please delete and otherwise erase it
and any attachments from your computer system. Your assistance in
correcting this error is appreciated.
--
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 thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.