POV-Ray : Newsgroups : povray.general : problem: repeating rand patterns using seed in animation : Re: problem: repeating rand patterns using seed in animation Server Time
30 Jul 2024 20:19:47 EDT (-0400)
  Re: problem: repeating rand patterns using seed in animation  
From: Warp
Date: 25 Jan 2009 08:39:39
Message: <497c6b9a@news.povray.org>

>         One way to work around this issue is to use two random streams: the
> first is seeded by a constant and read in the while loop with one
> iteration per frame, and the second is seeded from the first

  That would work if you used two *different* linear congruential generators.
However, since you are using the one and the same, I'm not sure it would
help anything.

  It is, in fact, possible to completely replicate POV-Ray's rand() in SDL:

#declare SeedValue = 0;
#macro GetRand()
  #declare SeedValue =
    mod(Int32Mul(SeedValue, 1812433253) + 12345, 4294967296);
  (SeedValue / 4294967295)
#end

#declare Int32Mul = function(v1, v2)
{
  mod(v1, 65536) * mod(v2, 65536) +
  mod(v1, 65536) * mod(int(v2/65536), 65536) * 65536 +
  mod(int(v1/65536), 65536) * mod(v2, 65536) * 65536
};

//--------------------------------------------------------------------
#declare POV_seed = seed(0);
#declare Ind = 0;
#while(Ind < 20)
  #declare SDL_rand = GetRand();
  #declare POV_rand = rand(POV_seed);

  #debug concat("SDL: ", str(SDL_rand, 0, 10),
                ", POV: ", str(POV_rand, 0, 10), "\n")

  #declare Ind = Ind + 1;
#end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.