[fpc-pascal] Re: Why is Random(255) some 529x slower compared to Delphi 7?
On Fri, 9 Dec 2011 13:28:49 +0100 (CET), Dimitri Smits smi...@telenet.be wrote: Randomize() is supposed to be called only once to seed the generator with an initial value. I do know that:) I made that mistake long time ago. What I thought was, that constantly setting RandSeed is somewhat like constantly calling Randomize. In the example code randseed was dependant of randomize output - which might or might not be as awful as randomize. And the graphical output was just really good illustration, why it was bad. -- Virgo Pärna virgo.pa...@mail.ee ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: Why is Random(255) some 529x slower compared to Delphi 7?
On Fri, 09 Dec 2011 09:19:53 +0100, Florian Klaempfl flor...@freepascal.org wrote: Oops, mails crossed. The assignment to randseed is indeed the problem. Why is it done? Bad random generator of delphi :)? I don't know, how bad Delphis random generator is, but I once years ago did make a mistake of calling randomize before random. It was a school assignment for using Turbo Pascal graphics. So I made program, that was supposed to fill screen with random dots (colour was also set with random). Anyway, when I called randomize before random, then as a result dots didn't fill the screen, but were mostly along the diagonal of the screen. So I'd guess, that setting randseed multiple times could be actually bad for randomness of results. Or maybe modern algorithms are better at situations like this? -- Virgo Pärna virgo.pa...@mail.ee ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: Why is Random(255) some 529x slower compared to Delphi 7?
- Virgo Pärna virgo.pa...@mail.ee schreef: On Fri, 09 Dec 2011 09:19:53 +0100, Florian Klaempfl flor...@freepascal.org wrote: Oops, mails crossed. The assignment to randseed is indeed the problem. Why is it done? Bad random generator of delphi :)? I don't know, how bad Delphis random generator is, but I once years ago did make a mistake of calling randomize before random. It was a school assignment for using Turbo Pascal graphics. So I made program, that was supposed to fill screen with random dots (colour was also set with random). Anyway, when I called randomize before random, then as a result dots didn't fill the screen, but were mostly along the diagonal of the screen. So I'd guess, that setting randseed multiple times could be actually bad for randomness of results. Or maybe modern algorithms are better at situations like this? Randomize() is supposed to be called only once to seed the generator with an initial value. If you made it something like so: begin for i := 0 to 1000 do begin randomize(); pixel[random(screenwidth),random(screenheight)]:= clSomeColor; end; end; then you seed with a timestamp before randoming and your distribution does not change much with a lcg. Not the fault of the algorithm itself, just your mistake of doing the randomize in the loop itself (like you mentioned yourself). kind regards, Dimitri Smits ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: Why is Random(255) some 529x slower compared to Delphi 7?
In our previous episode, Dimitri Smits said: Randomize() is supposed to be called only once to seed the generator with an initial value. If you made it something like so: begin for i := 0 to 1000 do begin randomize(); pixel[random(screenwidth),random(screenheight)]:= clSomeColor; end; end; then you seed with a timestamp before randoming and your distribution does not change much with a lcg. Not the fault of the algorithm itself, just your mistake of doing the randomize in the loop itself (like you mentioned yourself). (specially since high quality rng's might call OS dependent sources for initial entropy in that first call) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal