Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-12

Randomize

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Lv

Randomize seems to be 1 second dependent on the system clock. I cannot remember if this used to be the same in Borland Delphi/Pascal The example below shows a 1 second tick sensitivity to random number creation.

Am I missing something?

uses unix,crt;
VAR
   dummystring,filename	   : String;
   randomnumber	   : Int64;
   hellfreezesover : Boolean;
BEGIN
   hellfreezesover:=False;
   Repeat
   Randomize;Randomize;Randomize;Randomize;Randomize;
   randomnumber:=Random(9999999999999999999);
      writeln('randomnumber=',randomnumber);
   Until (hellfreezesover or keypressed);
END.

Reply by email

Lv

Randomize seems to be 1 second dependent on the system clock. I cannot remember if this used to be the same in Borland Delphi/Pascal The example below shows a 1 second tick sensitivity to random number creation.

Am I missing something?

uses unix,crt;
VAR
   dummystring,filename	   : String;
   randomnumber	   : Int64;
   hellfreezesover : Boolean;
BEGIN
   hellfreezesover:=False;
   Repeat
   Randomize;
   randomnumber:=Random(9999999999999999999);
      writeln('randomnumber=',randomnumber);
   Until (hellfreezesover or keypressed);
END.

Reply by email

Michael Van Canneyt
to Lv
Lv wrote 24 lines
Randomize seems to be 1 second dependent on the system clock. I cannot remember if this used to be the same in Borland Delphi/Pascal The example below shows a 1 second tick sensitivity to random number creation. Am I missing something? uses unix,crt; VAR dummystring,filename : String; randomnumber : Int64; hellfreezesover : Boolean; BEGIN hellfreezesover:=False; Repeat Randomize; randomnumber:=Random(9999999999999999999); writeln('randomnumber=',randomnumber); Until (hellfreezesover or keypressed); END.

This is normal behaviour. Randomize initializes the random seed with a value it retrieves from the clock. You must call Randomize exactly once in your program, never in a loop, something like this:

   Randomize;
   Repeat
    randomnumber:=Random(9999999999999999999);
    writeln('randomnumber=',randomnumber);
   Until (hellfreezesover or keypressed);

Michael.

Reply by email

andtag
to Lv: Randomize seems to be 1 second dependent on the system clock. I cannot remember if this…

Put randomize before of repeat

Lv ha scritto:

Show quoted text 31 lines
Randomize seems to be 1 second dependent on the system clock. I cannot remember if this used to be the same in Borland Delphi/Pascal The example below shows a 1 second tick sensitivity to random number creation. Am I missing something? uses unix,crt; VAR dummystring,filename : String; randomnumber : Int64; hellfreezesover : Boolean; BEGIN hellfreezesover:=False; Repeat Randomize; randomnumber:=Random(9999999999999999999); writeln('randomnumber=',randomnumber); Until (hellfreezesover or keypressed); END. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email