You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
print(":WARNING: Seeds equal to 0 are used if no seed is provided. This indicates to cxxrandom.plug.dll that the engine needs to be seeded with the current time.\nRecommendation: use a non-zero value for your seed, or don't provide a seed to use the time since epoch(1969~).")
end
returnGenerateEngine(seed)
elseiftype(seed) =='nil' then
returnGenerateEngine(0)
else
error("Argument `seed` must be a number, or nil.")
error("Invalid argument type (engineID): " ..tostring(engineID))
end
ifflagtype~='nil' andflagtype=='boolean' then
o.destroyid=destroyEngineOnDestruction
elseifflagtype=='nil' then
o.destroyid=true
else
error("Invalid arugment type (destroyEngineOnDestruction): " ..tostring(destroyEngineOnDestruction))
end
iftype(distrib) ~='nil' then
iftype(distrib) =='table' andtype(distrib.next) =='function' then
o.distrib=distrib
o.distrib.rngID=o.rngID
else
error("Invalid distribution used as an argument. Cannot set this as the number distribution.")
end
end
setmetatable(o,self)
returno
end
--crng destructor - we may need to destroy the engine, the user may be doing it manually though
functioncrng:__gc()
ifself.destroyidthen
DestroyEngine(self.rngID)
end
end
functioncrng:changeSeed(seed)
iftype(seed) =='number' then
ifseed==0then
print(":WARNING: Seeds equal to 0 are used if no seed is provided. This indicates to cxxrandom.plug.dll that the engine needs to be seeded with the current time.\nRecommendation: use a non-zero value for your seed, or don't provide a seed to use the time since epoch(1969~).")
end
returnNewSeed(self.rngID, seed)
elseiftype(seed) =='nil' then
returnNewSeed(self.rngID, 0)
else
error("Argument `seed` must be a number, or nil.")
end
end
functioncrng:setNumDistrib(distrib)
iftype(distrib) =='table' andtype(distrib.next) =='function' then
self.distrib=distrib
self.distrib.rngID=self.rngID
else
error("Invalid distribution used as an argument. Cannot set this as the number distribution.")
end
end
functioncrng:next()
iftype(self.distrib) =='table' andtype(self.distrib.next) =='function' then
returnself.distrib:next(self.rngID)
else
error("crng object does not have a valid number distribution set")
end
end
functioncrng:shuffle()
iftype(self.distrib) =='table' andtype(self.distrib.shuffle) =='function' then
self.distrib:shuffle(self.rngID)
else
print(":WARNING: No self.distrib.shuffle not found.")
changeSeed(0)
end
end
--Class: normal_distribution
----------------------------
normal_distribution= {}
functionnormal_distribution:new(avg, stddev)
localo= {}
self.__index=self
iftype(avg) ~='number' ortype(stddev) ~='number' then
error("Invalid arguments in normal_distribution construction. Average and standard deviation must be numbers.")
iftype(min) ~='number' ortype(max) ~='number' then
error("Invalid arguments in real_distribution construction. min and max must be numbers.")
end
o.min=min
o.max=max
setmetatable(o,self)
returno
end
functionreal_distribution:next(id)
returnrollDouble(id, self.min, self.max)
end
--Class: int_distribution
----------------------------
int_distribution= {}
functionint_distribution:new(min, max)
localo= {}
self.__index=self
iftype(min) ~='number' ortype(max) ~='number' then
error("Invalid arguments in int_distribution construction. min and max must be numbers.")
end
o.min=min
o.max=max
setmetatable(o,self)
returno
end
functionint_distribution:next(id)
returnrollInt(id, self.min, self.max)
end
--Class: bool_distribution
----------------------------
bool_distribution= {}
functionbool_distribution:new(chance)
localo= {}
self.__index=self
iftype(min) ~='number' ortype(max) ~='number' then
error("Invalid arguments in bool_distribution construction. min and max must be numbers.")
end
o.p=chance
setmetatable(o,self)
returno
end
functionbool_distribution:next(id)
returnrollBool(id, self.p)
end
--Class: num_sequence
----------------------------
num_sequence= {}
functionnum_sequence:new(a,b)
localo= {}
self.__index=self
localbtype=type(b)
localatype=type(a)
ifatype=='number' andbtype=='number' then
ifa==bthen
print(":WARNING: You've provided two equal arguments to initialize your sequence with. This is the mechanism used to indicate to cxxrandom.plug.dll that an empty sequence is desired.\nRecommendation: provide no arguments if you wish for an empty sequence.")
end
o.seqID=MakeNumSequence(a, b)
elseifatype=='table' then
o.seqID=MakeNumSequence(0,0)
for_,vinpairs(a) do
iftype(v) ~='number' then
error("num_sequence can only be initialized using numbers. " ..tostring(v) .." is not a number.")