Random numbers

Menu

When we want to have random numbers, we have to put a number in a seed declaration and do a random on this declaration.
Example:
#declare R = seed (125)
rand (R)

Whe we look at it more closely (Rand example), we see that the generated numbers are all the same till seed is the same!

To put this right, a small program (6.5kb) in Pascal mkseed.exe made by Jean-Michel Soler.
This program gets the hour under this form: h*60*60*100+m*60*100+s*100 and returns a text file, "vraigrai.txt" which thus contains a number changing all the time.
To generate it, you have to use the Pov shell_out command in a File.ini. To get this number, you have to open the vraigrai.txt file and read this number with the #fopen, #fclose, #read I/O directives as in this example.

//===============================================================//
// Example with the same seed
//===============================================================//
// Macro Randomize
//===============================================================//
#declare ra = seed(125);
#macro Rand0 (h);
#local rd = rand (ra);
#decalre rtn = rand (rd);
rtn
#end

#macro Rand();
#local rd = rand (ra);
Rand0 (Rand0 (rd) * Rand0 (rd))
#end
//======================== End macro ===============================//

//=============================== Example ==========================//
camera {
   location z*-40
   look_at 0
}

#declare i = 20;
#while (i > -40
sphere {
   <0,0,0>, 2
   pigment {rgb }
   translate x*-i
}
#declare i = i - 4;
#end
//============================== End example ========================//

//=============================== Seed.ini ==========================//
// Put in the same directory the program mkseed.exe and the files Seed.ini and Exp_random.pov
//===============================================================//
Pre_Scene_Command = mkseed.exe
input_File_Name = Exp_random.pov + a0.3 + w320 +h240 // all these values can be changed
//============================== End Seed.ini ========================//

//=========================== Exp_random.pov ========================//
// It can be a include file to put in the include directory
//================================================================//
// Macro Randomize
//============================= Open and read ========================//
#fopen GetSeed "vraigrai.text" read // the file with the random number is opened
#read (GetSeed, ra) // the random number is read
#fclose GetSeed
//============================ End reading ===========================//
#declare ra = seed (ra); // the number is put in the seed
#macro Rand0 (h)
#local rd = rand (ra);
#decalre rtn = rand (rd);
rtn
#end

#macro Rand()
#local rd = rand (ra);
Rand0 (Rand0 (rd) * Rand0 (rd))
#end
//============================= End macro ===========================//

//=============================== Example ===========================//
// #include "random.inc"

camera {
   location z*-40
   look_at 0
}

light_source {<0, 10, -100> rgb 2}

#declare i = 20;
#while (i > -40)
sphere {
   <0,0,0>, 2
   pigment {rgb }
   translate x*-i
}
#declare i = i - 4;
#end
//============================= End example ============================//