POV-Ray : Newsgroups : povray.text.scene-files : self-reseeding randomness Server Time
31 Oct 2024 08:16:17 EDT (-0400)
  self-reseeding randomness (Message 1 to 2 of 2)  
From: Pete
Subject: self-reseeding randomness
Date: 23 Dec 2000 21:58:06
Message: <1577.392T2347T13115192PeterC@nym.alias.net>
/*
random.inc

        This include file allows for a self-reseeding random
number.  When you use the two macros, your scene starts with
a different random number each time.  It works be creating
and using a file called "randseed.pov".  the get_seed()
function includes randseed.pov and the update_seed()
function writes the new seed into randseed.pov.  On the
windows function I can ust hit alt-G every time I want to
change the randomness.  Enjoy!
        Note: the first time you use the macros, the error
message will come up.  THis is because randseed.pov does
not exist yet.  This is ok.  You should only see it once.
        Further note: call get_seed() at the top of your .pov
file and call update_seed() at the very very end of your .pov
file.
        Last note:  tested on OFFICIAL povray 3.1 on windows
and miggy.  Should be fine on Mac??

Pete
*/


// get seed from the seed file and seed rseed with it
#macro get_seed()
  #if (file_exists("randseed.pov") = 1)
    #include "randseed.pov"
  #end
  #ifndef (rseed)
    #render "\nrseed not set - serious error.  Faking it\n"
    #declare rseed = seed(39631791);  // any 8 digit number
  #end
#end


// update the random seed now that we are done with it.
#macro update_seed()
  #ifdef (rseed)
    #local new_seed = 99999999 * rand(rseed);
    #local new_seed = int(new_seed);
    #fopen F1 "randseed.pov" write
    #write (F1, "#declare rseed = seed(", str(new_seed, 0, 0), ");\n")
    #write (F1, "#render \" Seed used is: ", str(new_seed, 0, 0), "\"\n")
    #fclose F1
  #end
#end


/* actual end of this file */


Post a reply to this message

From: Pete
Subject: Re: self-reseeding randomness
Date: 24 Dec 2000 23:27:08
Message: <246.393T2042T9165707PeterC@nym.alias.net>
Forgot to mention one thing: the include uses the
variable "rseed" as the random seed, so if you use this
include, you need pass rseed as the seed to the rand()
function. in other words:

 #declare some_random_value = rand(rseed);


Pete


Post a reply to this message

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