[Openroad-users] Random Function

Kim Ginnerup kgi at bording.dk
Thu Jan 10 17:24:02 EST 2008


OpenROAD has an undocumented random function.
You can find it the Ingres SDK in the Tetris application.
So you can say that CA at that point actually showed the function to the public.
Whether you want to use it is your decision

procedure main
(
) =
declare
            i = integer not null;
            r = integer not null;
enddeclare
{
            curprocedure.trace('Start');
            // Seed getRandomInteger()
            GV_I_RN_SEED = date_part('sec', date('now'));
// or use this if you want to include 3GL
GV_I_RN_SEED = GetTickCount();

            // will return integer between 0 and maxNumber
            for i = 1 to 10 do
                        r = getRandomInteger(maxNumber = 100);
                        curprocedure.trace(varchar(r));
            endfor;
}

________________________________
Fra: openroad-users-bounces at peerlessit.com [mailto:openroad-users-bounces at peerlessit.com] På vegne af Doug White
Sendt: 10. januar 2008 03:09
Til: International OpenROAD Users
Emne: Re: [Openroad-users] Random Function

Sorry i wasnt very clear in my last email... how do i input the return of this function into the OpenROAD random function. How do i randomize the seed for the OpenROAD function with this value?
__ÐöUgWa__

________________________________
Date: Tue, 8 Jan 2008 11:21:08 +0000
From: gareth.2.edwards at bt.com
To: openroad-users at peerlessit.com
Subject: Re: [Openroad-users] Random Function
Setup a 3GL proc: GetTickCount, Library = Kernel32.dll, return type: integer.

Then in code:
Result = GetTickCount();


Cheers,
Gareth Edwards
BT Global Services
tel: +44 (0)131 345 3629
email: gareth.2.edwards at bt.com<mailto:gareth.2.edwards at bt.com>


________________________________
From: openroad-users-bounces at peerlessit.com [mailto:openroad-users-bounces at peerlessit.com] On Behalf Of Doug White
Sent: Sunday, December 16, 2007 10:46 PM
To: International OpenROAD Users
Subject: Re: [Openroad-users] Random Function
Ok, forgive me, i'm slow... how do i use the GetTickCount() to start the seed values for the openroad random function...

I can't find any documentation on these functions in the OpenROAD manuals
Doug White

________________________________
Date: Sat, 15 Dec 2007 19:31:39 -0500
From: David.Tondreau at ingres.com
To: openroad-users at peerlessit.com
Subject: Re: [Openroad-users] Random Function
GetTickCount() returns the number of milliseconds since the system was started which should be reasonably random...

http://msdn2.microsoft.com/en-us/library/ms724408.aspx

Regards,
David
David Tondreau
Architect, Ingres Corp.
http://community.ingres.com/



From: openroad-users-bounces at peerlessit.com [mailto:openroad-users-bounces at peerlessit.com] On Behalf Of Paul White
Sent: Friday, December 14, 2007 11:23 PM
To: International OpenROAD Users
Subject: Re: [Openroad-users] Random Function

What about date_part(seconds,date('now)) ?  (combined with some other date/time values)

I wonder if we can get access to time values in milliseconds.
The OpenROAD profiling tracks time in milliseconds.

And I suppose you could use there is a WinAPI call to retrieve the full system time.



________________________________
From: openroad-users-bounces at peerlessit.com [mailto:openroad-users-bounces at peerlessit.com] On Behalf Of Doug White
Sent: Saturday, 15 December 2007 2:12 PM
To: International OpenROAD Users
Subject: Re: [Openroad-users] Random Function
That is much nicer,

Is there a way I can get a random seed if my app doesn't connect to a database?
Doug

________________________________
Date: Fri, 14 Dec 2007 08:14:39 -0500
From: Sean.Thrower at ingres.com
To: openroad-users at peerlessit.com
Subject: Re: [Openroad-users] Random Function
Apologies - I should have been clearer - I meant that you use the OpenROAD-local random() function throughout, having first got a random seed from the database call: but you do it by using each locally-generated random number to set limits for the next one, so as to avoid the situation where  the OpenROAD-local random() starts from the same seed each time at application startup.

Initially:-
query = 'SET RANDOM_SEED ' + :whatever;                                        //optional
EXECUTE IMMEDIATE :query;                                                              //optional
SELECT random(:low, :high) AS randy;

Thereafter:-
low = lowfunction(randy); high = highfunction(randy);
randy = random( :low, :high);

On reflection, it may even suffice to base the limits on the database-generated seed just once, since thereafter the random number sequence is emerging from a randomly chosen limit-set, so is randomly different from every other application startup.

Initially:-
query = 'SET RANDOM_SEED ' + :whatever;                                        //optional
EXECUTE IMMEDIATE :query;                                                              //optional
SELECT random(:low, :high) AS randy;
low = lowfunction(randy); high = highfunction(randy);
randy = random( :low, :high);

Thereafter:-
randy = random( :low, :high);

Sean.

________________________________
From: openroad-users-bounces at peerlessit.com [mailto:openroad-users-bounces at peerlessit.com] On Behalf Of Kim Ginnerup
Sent: Friday, December 14, 2007 12:01 PM
To: International OpenROAD Users
Subject: Re: [Openroad-users] Random Function

If you can find the old tetris demo app for OpenROAD
You will find that OpenROAD actually has a built in random function

Kim

________________________________
Fra: openroad-users-bounces at peerlessit.com [mailto:openroad-users-bounces at peerlessit.com] På vegne af Sean Thrower
Sendt: 14. december 2007 12:12
Til: International OpenROAD Users
Emne: Re: [Openroad-users] Random Function

Or maybe use the execute immediate select just to get the first random number, then derive the next limit-values from each random value in turn - random()-generated values from random limits should be random ... - using Mod if necessary to bring the final working value into range.

Sean.

Sean Thrower
Ingres Premium Services


________________________________
From: openroad-users-bounces at peerlessit.com [mailto:openroad-users-bounces at peerlessit.com] On Behalf Of Bodo Bergmann
Sent: Friday, December 14, 2007 9:01 AM
To: International OpenROAD Users
Subject: Re: [Openroad-users] Random Function

Or you coud just use the Ingres random() functions (see SQL Ref Manual)
using a select (Execute Immediate if not supported directly).

Bodo Bergmann
Senior Software Engineer
OpenROAD Worldwide Engineering
Ingres Corp.

________________________________
From: openroad-users-bounces at peerlessit.com [mailto:openroad-users-bounces at peerlessit.com] On Behalf Of Doug White
Sent: Friday, December 14, 2007 9:02 AM
To: openroad
Subject: [Openroad-users] Random Function
Hey All,

I finally got sick of the crappy support for random number generation in OpenROAD, So hopefully this can be of use to someone.

Enjoy, and please email me if you spot any problems / improvements that can be fixed

P.S It's an exported application, that will probably only work in XP
Doug White

________________________________
Listen now! New music from the Rogue Traders.<http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=832&referral=hotmailtaglineOct07&URL=http://music.ninemsn.com.au/roguetraders>

________________________________
Find it at www.seek.com.au Your Future Starts Here. Dream it? Then be it!<http://a.ninemsn.com.au/b.aspx?URL=http://ninemsn.seek.com.au/?tracking%3Dsk:het:sk:nine:0:hot:text&_t=764565661&_r=OCT07_endtext_Future&_m=EXT>

________________________________
Check our comprehensive Salary Centre Overpaid or Underpaid?<http://a.ninemsn.com.au/b.aspx?URL=http://content.mycareer.com.au/salary-centre?s_cid%3D595810&_t=766724125&_r=Hotmail_Email_Tagline_MyCareer_Oct07&_m=EXT>

________________________________
Check our comprehensive Salary Centre Overpaid or Underpaid?<http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fcontent%2Emycareer%2Ecom%2Eau%2Fsalary%2Dcentre%3Fs%5Fcid%3D595810&_t=766724125&_r=Hotmail_Email_Tagline_MyCareer_Oct07&_m=EXT>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.peerlessit.com/pipermail/openroad-users/attachments/20080110/0a76d616/attachment.html 


More information about the Openroad-users mailing list