|
|
Am 19.02.2018 um 13:21 schrieb Anthraqunione:
> Povray 3.7
>
> I want an 8 digit random interger and used thisi code
>
> #declare Random = true; // User random number for image
> #declare Seed = 1001011;
> #if (Random = true)
> #local R = seed (Seed);
> #declare S = rand(R);
> #declare S = int(S*100000000);
> #end
>
> I started with Seed = 1 and was planning to work upwards as I expected each
> final number the be "random". I found the final 2 or 3 digits repeated and
> started trying different values of Seed. This is what I got
You're using the pseudorandom number generator wrong. Traditional
(non-cryptographic) pseudorandom number generators (such as the one in
POV-Ray) are designed to produce streams of numbers that have
pseudorandom properties /within that stream/, but not necessarily
/between streams/ with different seeds.
Especially the first numbers pulled from such a pair of such streams may
exhibit noticeable similarities when the seeds are similar.
To get any reasonable randomness out of the approach you're using, you'd
need to pull and discard the first few random numbers from the stream, e.g.:
#declare Random = true;
#declare Seed = 1001011;
#if (Random = true)
#local R = seed (Seed);
#for (I,1,10)
#declare Dummy = rand(R);
#end
#declare S = rand(R);
#declare S = int(S*100000000);
#end
However, the proper way to make use of POV-Ray's pseudorandom number
generator would be to use just one seed, and pull actual sequences out
of the generator; e.g.:
#declare Random = true;
#declare Seed = 1001011;
#if (Random = true)
#local R = seed (Seed);
#for (I,1,100000)
#declare S = rand(R);
#declare S = int(S*100000000);
// actually do something with S here
#end
#end
If you can't do this because you just need one random number for each
frame of an animation, possibly the fastest solution would be to skip
`frame_number` random numbers each time the scene is parsed, e.g.:
#declare Random = true;
#declare Seed = 1001011; // keep same for all frames
#if (Random = true)
#local R = seed (Seed);
#for (I,1,frame_number)
#declare Dummy = rand(R);
#end
#declare S = rand(R);
#declare S = int(S*100000000);
#end
If you want to stick to your approach, instead of seeding a pseudorandom
number generator and pulling a single value you should use a hash
function instead and apply it to the "seed" (CRC32 might do). You'll
have to program the has function yourself though, as there's none built
into POV-Ray.
Post a reply to this message
|
|