Am 09.12.2011 09:02, schrieb Vincent Snijders: > 2011/12/7 Graeme Geldenhuys <graemeg.li...@gmail.com>: >> Hi, >> >> I did a simple GetTickCount() timing around this loop. Delphi executes >> the loop in 20 ticks. FPC 2.6.0-rc2 takes 10585 ticks!!!! The outer >> loop runs 200400 iterations. The types for BitValue, ByteValue and >> RandSeed is of type Byte. >> >> 01 for Index := 1 to Length(Source) do >> 02 begin >> 03 OrdValue := Ord(Source[Index]); >> 04 for BitCount := 0 to 7 do >> 05 begin >> 06 BitValue := Byte(OrdValue and (1 shl BitCount) = 1 shl BitCount); >> 07 RandSeed := ByteValue; >> 08 ByteValue := (((Random(255) + 1) div 2) * 2) + BitValue; >> 09 Result[(Index - 1) * 8 + BitCount + 1] := AnsiChar(ByteValue); >> 10 end; >> 11 end; >> > > I have one question about this code, why is RandSeed set inside the > loop and not outside the loop or even at the program start? > If you change the randseed, then the random number generator has to be > initialized and that is more costly for a stateful RNG as the mersenne > twister.
Oops, mails crossed. The assignment to randseed is indeed the problem. Why is it done? Bad random generator of delphi :)? _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal