Strange behaviour, Ado + RandG (Can someone explain please?)

aymimi_at_yahoo.com
Date: 12/13/04

  • Next message: Bill Todd: "Re: ADO in D2005"
    Date: Mon, 13 Dec 2004 12:51:47 +0300
    
    

    It appear that after call to the 'Open' method of TCustomADODataset (called
    by LoadFromFile method) is used to open a saved recordset in a file, the
    behaviour of RandG function, with the same seed, changes!

    The behavious can be reproduced using this code:
    (*
     Open an ado dataset (like TADOQuery) from any database, then use the
    SaveToFile() method to save it to a file, say 'tmp.tmp'. Then Call
    GenerateRandomText and observer what it returns. U could use its md5 hash to
    make things easier.

    Then use LoadFromFile method of an Ado dataset to load the file. Then call
    GenerateRandomText with the same parameters. Now the returned text is
    changed (only once) to something else forver untill u restart the program.*)

    {Start of code}
    uses SysUtils,Math, ADODB;

    function GenerateRandomText(ASeed, ACount:Integer; AMean,
    AStdDev:Extended):String;
    var i:Integer;
    begin
         result:='';
         RandSeed:=ASeed;
         for i:=0 to ACount-1 do
           begin
                result:=result+FloatToStr(RandG(AMean, AStdDev));
           end;
         //result:=md5(result);
    end;

    const
         ASeed = 54321; //1235,100,67,90
         ACount = 100;
         AMean = 67;
         AStdDev = 90;

    function TestEqualness(UseADO:Boolean):Boolean;
    var txt1,txt2:String;
        q:TADOQuery;
    begin
         txt1:=GenerateRandomText(ASeed,ACount,AMean,AStdDev);
         if UseADO then
            begin
                 q:=TADOQuery.Create(nil);
                 try
                    q.LoadFromFile('tmp.tmp');
                 finally
                   q.Free;
                 end;
            end;
         txt2:=GenerateRandomText(ASeed,ACount,AMean,AStdDev);
         result:=CompareText(txt1,txt2)=0;
    end;

    {End of code}
    the values generated by GenerateRandomText before using LoadFromFile()
    method are the same. after u call LoadFromFile() the values produced are
    again the same but different from those produced before calling
    LoadFromFile().

    I would appreciate if at least someone explain this strange behaviour.

    Arnold.


  • Next message: Bill Todd: "Re: ADO in D2005"