dmj5
Class DMJ_GeneratorRandom

Object
  extended by common:Generic
      extended by common:Generator
          extended by dmj5:DMJ_GeneratorRandom
Direct Known Subclasses:
DMJ_GeneratorRandom2, DMJ_GeneratorRandom3

class 
Generator:DMJ_GeneratorRandom

This Generator produces a random sequence. The random number generator is very simple and quick.


Ultra Fractal Source

Toggle UF Source Code Display

 class DMJ_GeneratorRandom(common.ulb:Generator) {
   ; This Generator produces a random sequence. The random number generator is very simple and quick.
   
 public:
   import "common.ulb"
   
   ; Constructor
   ; @param pparent = a reference to the object creating the new object; typically, 'this'
   func DMJ_GeneratorRandom(Generic pparent)
     Generator.Generator(pparent)
   endfunc
   
   ; Set up for a sequence of values
   ;
   ; This function will be called at the beginning of each
   ; sequence of values (e.g. at the beginning of each fractal
   ; orbit).
   ; @param pz = seed value for the sequence
   ; @return first value in the sequence
   float func Init(float pz)
     Generator.Init(pz)
     
     ; Base class implementation flags the sequence to end
     ; immediately. We don't want this (this sequence proceeds
     ; indefinitely) so clear the flag.
     m_BailedOut = false
     return pz
   endfunc
 
   ; Set up for a sequence of values
   ;
   ; This alternate form of Init will cause the Generator to
   ; start with its "default" sequence. This can be used if a
   ; generator allows a user to select a "seed" value itself.
   ; Such Generator classes should override this function.
   ; @return first value in the sequence
   float func InitDefault()
     return Init(@p_seed / 2147483648.0)
   endfunc
   
   ; Produce the next value in the sequence
   ;
   float func Iterate(float pz)
     Generator.Iterate(pz)
 
     pz = pz * 2147483648.0
     pz = (pz * 1103515245 + 12345) % 2147483648.0
     pz = pz / 2147483648.0
     return pz
   endfunc
   
 protected:
 
 default:
   title = "Random"
   
   int param v_dmj_generatorrandom
     caption = "Version (DMJ_GeneratorRandom)"
     default = 100
     hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used."
     visible = @v_dmj_generatorrandom < 100
   endparam
 
   int param p_seed
     caption = "Seed"
     default = 51853571
     hint = "Sets the seed for the random number generator. Each different seed produces a different sequence of random values."
   endparam
 }
 


Constructor Summary
DMJ_GeneratorRandom()
           
DMJ_GeneratorRandom(Generic pparent)
          Constructor
 
Method Summary
 float Init(float pz)
          Set up for a sequence of values This function will be called at the beginning of each sequence of values (e.g.
 float InitDefault()
          Set up for a sequence of values This alternate form of Init will cause the Generator to start with its "default" sequence.
 float Iterate(float pz)
          Produce the next value in the sequence
 
Methods inherited from class common:Generator
IsBailedOut
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

DMJ_GeneratorRandom

public DMJ_GeneratorRandom(Generic pparent)
Constructor

Parameters:
pparent - = a reference to the object creating the new object; typically, 'this'

DMJ_GeneratorRandom

public DMJ_GeneratorRandom()
Method Detail

Init

public float Init(float pz)
Set up for a sequence of values This function will be called at the beginning of each sequence of values (e.g. at the beginning of each fractal orbit).

Overrides:
Init in class Generator
Parameters:
pz - = seed value for the sequence
Returns:
first value in the sequence

InitDefault

public float InitDefault()
Set up for a sequence of values This alternate form of Init will cause the Generator to start with its "default" sequence. This can be used if a generator allows a user to select a "seed" value itself. Such Generator classes should override this function.

Overrides:
InitDefault in class Generator
Returns:
first value in the sequence

Iterate

public float Iterate(float pz)
Produce the next value in the sequence

Overrides:
Iterate in class Generator
Parameters:
pz - previous value in the sequence. Note that you should always use this value for computing the next iteration, rather than a saved value, as the calling code may modify the returned value before passing it back to the next Iterate() call.
Returns:
the next value in the sequence