Albert, your solution looks pretty good.  However, when I "played" with
it, I found something interesting.  When I am having problems with a
statement or trying to learn how something works, I often break apart
the complex portions into their "atomic units".  While doing this with
your approach I observed something that, to me, is very subtle and very
discrete about SELECT-processing versus FUNCTION-processing.

>From the SELECT below, notice that the values for #TIME are constant; I
assume that by whatever means the parsing and processing work within
RBase (or any other DBMS, probably) the value for this is fixed at some
point therein.  

However, you can see that both (TEXTRACT(.#NOW)) as well as your input
to RANDOM, (FLOAT(format(.#time,'hhmmss.ss'))) process once for each row
in the result-set.  ALSO, for further observation, when I replicated
these sets of values (%NUM and %Result 2 & 3), it seems that those
function calls are likewise executed each time they are called within a
row of the result.  In this case, 3 times, which is as one would expect,
such as when using a stored procedure.  This successive execution by
call within each row also demonstrates that RANDOM() appears to function
as advertised.  Although I haven't saved/assessed the data to prove
this, the limited matrix generated below shows no duplicate values,
based on an "eyeball" of the result-set.
 
I'm sure it's all correct for how a dbms engine (and other functionality
associated with the implementation) but I found it curious and thought
that maybe others might learn from this little demonstration of nuance,
as I just did.  

R>sho time
 TIME format     HH:MM:SS.SSS
 TIME sequence   HHMMSS

R>select .#TIME AS #TIME, (TEXTRACT(.#NOW)) AS TIME_fm_#NOW,
(FLOAT(format(.#time,'hhmmss.sss'))) AS AlbertsNUM1, (random(INT(1000 *
(FLOAT(format(.#time,'hhmmss.sss')))))) AS RandomNUM1,
(FLOAT(format(.#time,'hhmmss.sss'))) AS AlbertsNUM2, (random(INT(1000 *
(FLOAT(format(.#time,'hhmmss.sss')))))) AS RandomNUM2,
(FLOAT(format(.#time,'hhmmss.sss'))) AS AlbertsNUM3, (random(INT(1000 *
(FLOAT(format(.#time,'hhmmss.sss')))))) AS RandomNUM3 from sys_tables

 #TIME           TIME_fm_#NOW AlbertsNUM1     RandomNUM1 AlbertsNUM2
RandomNUM2 AlbertsNUM3     RandomNUM3
 --------------- ------------ --------------- ---------- ---------------
---------- --------------- ---------- 
 13:49:30.360    13:49:30.361      134930.361   72221179      134930.361
111570377      134930.361   65546310
 13:49:30.360    13:49:30.440       134930.44   50969512       134930.44
112665764       134930.44   40864553
 13:49:30.360    13:49:30.462      134930.462   96252427      134930.462
17788683      134930.462   55457869
 13:49:30.360    13:49:30.479      134930.479   15672161      134930.479
33794386      134930.479  132414532
 13:49:30.360    13:49:30.497      134930.497    7716667      134930.497
115206464      134930.497   75795460
 ...
 13:50:19.637    13:50:23.832      135023.832   94740843      135023.833
23392648      135023.833   40480778
 13:50:19.637    13:50:23.851      135023.851  102491706      135023.851
50382587      135023.851   12332958
 13:50:19.637    13:50:23.870       135023.87   48042092       135023.87
21727931       135023.87  106591719



Just sittin' here watchin' the world go by ...
Steve in Memphis


-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Albert
Berry
Sent: Tuesday, April 08, 2008 12:11 PM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Re: [SPAM] [RBASE-L] - Random numbers

R:Base uses a pseudo random number generator. You can use the system 
time variable to the 1/1,000 second to generate pseudo random numbers 
that are for all intents and purposes random. Here is an example

select (random(INT(1000 * (FLOAT(format(.#time,"hhmmss.sss")))))) from 
sys_tables where count = 1



Marc wrote:
> I just tested this 3 times and get the same numbers each time.
> I am setting the Random number to 15 and created 10
> The numbers I get are
> 0 0 5 0 5 3 8 2 10 14 each of the 3 times I tested this.
>
> I hope I am missing something, I sent an update out several months
> back that needs truley random numbers.
>
> Marc
>


Reply via email to