pwxlib  0.8.9
Tools Library for C++ Development
pwx::CRandom Class Reference

Static class to produce unique or pseudo random numbers, hashes and names. More...

#include <pwxCRandom.h>

+ Inheritance diagram for pwx::CRandom:
+ Collaboration diagram for pwx::CRandom:

Public Types

typedef std::mutex lock_t
 Use standard mutex if no spinlocks are used.
 

Public Member Functions

 CRandom () noexcept
 default ctor More...
 
 CRandom (const CRandom &) PWX_DELETE
 
 ~CRandom () noexcept
 default dtor More...
 
int32_t getSeed () const noexcept
 return current seed More...
 
uint32_t hash (int16_t key) const noexcept
 hash an unsigned 16 bit integer to an unsigned 32 bit integer More...
 
uint32_t hash (uint16_t key) const noexcept
 hash a signed 16 bit integer to an unsigned 32 bit integer More...
 
uint32_t hash (int32_t key) const noexcept
 hash a signed 32 bit integer to an unsigned 32 bit integer More...
 
uint32_t hash (uint32_t key) const noexcept
 hash an unsigned 32 bit integer to an unsigned 32 bit integer More...
 
uint32_t hash (int64_t key) const noexcept
 hash a signed 64 bit integer to an unsigned 32 bit integer More...
 
uint32_t hash (uint64_t key) const noexcept
 hash an unsigned 64 bit integer to an unsigned 32 bit integer More...
 
uint32_t hash (float key) const noexcept
 hash float to an unsigned 32 bit integer More...
 
uint32_t hash (double key) const noexcept
 hash double to an unsigned 32 bit integer More...
 
uint32_t hash (long double key) const noexcept
 hash long double to an unsigned 32 bit integer More...
 
uint32_t hash (const char *key, size_t keyLen=0) const noexcept
 hash C-String to an unsigned 32 bit integer More...
 
uint32_t hash (std::string &key) const noexcept
 hash an std::string to an unsigned 32 bit integer More...
 
eNameSourceType nextNST (void) noexcept
 Switches to the next [N]ame[S]ource[T]ype and returns that. More...
 
double noise (int32_t x) const noexcept
 noise with one dimension More...
 
double noise (int32_t x, int32_t y) const noexcept
 noise with two dimensions More...
 
double noise (int32_t x, int32_t y, int32_t z) const noexcept
 noise with three dimensions More...
 
double noise (int32_t x, int32_t y, int32_t z, int32_t w) const noexcept
 noise with four dimensions More...
 
eNameSourceType prevNST (void) noexcept
 Switches to the previous [N]ame[S]ource[T]ype and returns that. More...
 
int16_t random (int16_t max) noexcept
 Generate a random value of int16_t between 0 and max. More...
 
int16_t random (int16_t min, int16_t max) noexcept
 Generate a random value of int16_t between min and max. More...
 
uint16_t random (uint16_t max) noexcept
 Generate a random value of uint16_t between 0 and max. More...
 
uint16_t random (uint16_t min, uint16_t max) noexcept
 Generate a random value of uint16_t between min and max. More...
 
int32_t random (int32_t max=RAND_MAX) noexcept
 Generate a random value of int32_t between 0 and max. More...
 
int32_t random (int32_t min, int32_t max) noexcept
 Generate a random value of int32_t between min and max. More...
 
uint32_t random (uint32_t max=RAND_MAX) noexcept
 Generate a random value of uint32_t between 0 and max. More...
 
uint32_t random (uint32_t min, uint32_t max) noexcept
 Generate a random value of uint32_t between min and max. More...
 
int64_t random (int64_t max) noexcept
 Generate a random value of int64_t between 0 and max. More...
 
int64_t random (int64_t min, int64_t max) noexcept
 Generate a random value of int64_t between min and max. More...
 
uint64_t random (uint64_t max) noexcept
 Generate a random value of uint64_t between 0 and max. More...
 
uint64_t random (uint64_t min, uint64_t max) noexcept
 Generate a random value of uint64_t between min and max. More...
 
float random (float max) noexcept
 Generate a random value of float between 0 and max. More...
 
float random (float min, float max) noexcept
 Generate a random value of float between min and max. More...
 
double random (double max) noexcept
 Generate a random value of double between 0 and max. More...
 
double random (double min, double max) noexcept
 Generate a random value of double between min and max. More...
 
long double random (long double max) noexcept
 Generate a random value of long double between 0 and max. More...
 
long double random (long double min, long double max) noexcept
 Generate a random value of long double between min and max. More...
 
size_t random (char *dest, size_t minLen, size_t maxLen) noexcept
 Generates a random C-String with minLen to maxLen characters. More...
 
char * rndName (double x, bool lN=false, bool mW=false) noexcept
 get random name (1D) More...
 
char * rndName (double x, double y, bool lN=false, bool mW=false) noexcept
 get random name (2D) More...
 
char * rndName (double x, double y, double z, bool lN=false, bool mW=false) noexcept
 get random name (3D) More...
 
char * rndName (double x, double y, double z, double w, bool lN=false, bool mW=false) noexcept
 get random name (4D) More...
 
char * rndName (double x, int32_t chars, int32_t sylls, int32_t parts) noexcept
 get random name (1D) More...
 
char * rndName (double x, double y, int32_t chars, int32_t sylls, int32_t parts) noexcept
 get random name (2D) More...
 
char * rndName (double x, double y, double z, int32_t chars, int32_t sylls, int32_t parts) noexcept
 get random name (3D) More...
 
char * rndName (double x, double y, double z, double w, int32_t chars, int32_t sylls, int32_t parts) noexcept
 get random name More...
 
void setNST (eNameSourceType type) noexcept
 set name source type to type More...
 
void setSeed (int32_t newSeed) noexcept
 set Simplex Seed More...
 
double simplex1D (double x, double zoom=1.0, double smooth=1.0) noexcept
 calculate a one dimensional simplex noise value More...
 
double simplex1D (double x, double zoom, double smooth, double reduction, int32_t waves) noexcept
 calculate a one dimensional simplex wave More...
 
double simplex2D (double x, double y, double zoom=1.0, double smooth=1.0) noexcept
 calculate a two dimensional simplex noise value More...
 
double simplex2D (double x, double y, double zoom, double smooth, double reduction, int32_t waves) noexcept
 calculate a two dimensional simplex wave More...
 
double simplex3D (double x, double y, double z, double zoom=1.0, double smooth=1.0) noexcept
 calculate a three dimensional simplex noise value More...
 
double simplex3D (double x, double y, double z, double zoom, double smooth, double reduction, int32_t waves) noexcept
 calculate a three dimensional simplex wave More...
 
double simplex4D (double x, double y, double z, double w, double zoom=1.0, double smooth=1.0) noexcept
 calculate a four dimensional simplex noise value More...
 
double simplex4D (double x, double y, double z, double w, double zoom, double smooth, double reduction, int32_t waves) noexcept
 calculate a four dimensional simplex wave More...
 
CRandomoperator= (const CRandom &) PWX_DELETE
 
bool beThreadSafe () const noexcept
 true if thread safety is turned on More...
 
void beThreadSafe (bool doLock) noexcept
 set thread safety to doLock More...
 
bool clear_locks () noexcept
 remove all locks More...
 
bool destroyed () const noexcept
 if true the object will no longer lock More...
 
void do_locking (bool doLock) noexcept
 set thread safety to doLock More...
 
bool is_locked () const noexcept
 return true if this object is locked More...
 
bool is_locking () const noexcept
 true if thread safety is turned on More...
 
void lock () noexcept
 lock this object More...
 
uint32_t lock_count () const noexcept
 number of locks this thread holds on this object More...
 
bool try_lock () noexcept
 try to lock and return at once More...
 
void unlock () noexcept
 unlock this object More...
 

Protected Attributes

abool_t isDestroyed = ATOMIC_VAR_INIT(false)
 Should be set to true by the destructors of deriving classes.
 
mord_t memOrdLoad = PWX_MEMORDER_ACQUIRE
 to be used with atomic::load()
 
mord_t memOrdStore = PWX_MEMORDER_RELEASE
 to be used with atomic::store()
 

Detailed Description

Static class to produce unique or pseudo random numbers, hashes and names.

This class produces a static instance called pwx::RNG, meaning "Random Name/Noise/Number Generator".

The following sets of functions are available:

  • random() These return random numbers as int32_t, int64_t, float, double and long double. They can be used without or with up to two arguments to get results between those two or from zero to the one argument.
  • hash() Hash functions for integer arguments, mostly taken from: http://www.burtleburtle.net/bob/hash/index.html (Robert Jenkins) http://www.cris.com/~Ttwang/tech/inthash.htm (Thomas Wang) The hash functions for strings and floating point numbers are of my own invention. The result is always an uint32_t.
  • noise() These are not the classic Perlin noise functions, but simple wrappers that transform hash() results into a -1.0 to 1.0 double range.
  • simplex() This set of functions produce pseudo random numbers using Simplex Noise (2D, 3D and 4D) by Ken Perlin, and are called simplex(). The documentation is taken from: http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf (Stefan Gustavson)
  • rndName() A method that returns a random name built by combining random letters into syllables. Important: The returned name is a malloc'd C-String. You are responsible to free it after usage!

Constructor & Destructor Documentation

◆ CRandom()

pwx::CRandom::CRandom ( )
explicitnoexcept

default ctor

Initializes the random number generator and assigns a first random value to lastRndValue. The seed and Simplex data are initialized as well.

◆ ~CRandom()

pwx::CRandom::~CRandom ( )
noexcept

default dtor

Empty default dtor, nothing to be done.

Member Function Documentation

◆ beThreadSafe() [1/2]

◆ beThreadSafe() [2/2]

void pwx::CLockable::beThreadSafe ( bool  doLock)
noexceptinherited

set thread safety to doLock

set thread safety mode to doLock This is just an alias for do_locking().

◆ clear_locks()

bool pwx::CLockable::clear_locks ( )
noexceptinherited

remove all locks

clear all locks from this thread.

If this thread is the current owner of the lock, and if there are locks in place, they are all cleared.

If this thread is not the owner, the method simply returns false.

Returns
true if this thread is the owner and all locks could be cleared.

References CURRENT_THREAD_ID.

◆ destroyed()

bool pwx::CLockable::destroyed ( ) const
noexceptinherited

if true the object will no longer lock

returns true if the data was destroyed

The destructor of TSingleElement and TDoubleElement will try to get a final lock on the element when it is destroyed. If another thread acquires a lock between the data destruction and this final dtor lock, destroyed() will return "true".

Returns
true if the element is within its destruction process.

References pwx::CLockable::isDestroyed, and pwx::CLockable::memOrdLoad.

Referenced by pwx::TSingleElement< data_t >::insertBefore(), pwx::THashElement< size_t, curr_t >::insertNext(), pwx::TDoubleElement< data_t >::insertNext(), pwx::TSingleElement< data_t >::insertNext(), and pwx::TDoubleElement< data_t >::insertPrev().

+ Here is the caller graph for this function:

◆ do_locking()

void pwx::CLockable::do_locking ( bool  doLock)
noexceptinherited

set thread safety to doLock

switch whether to really use locking or not.

With this method you can switch the locking mechanics on/off for objects to be used in concurrency or strictly single threaded. The default is to turn locking on.

Parameters
[in]doLocktrue to turn locking on, false to turn it off.

References CURRENT_THREAD_ID.

Referenced by pwx::VElement::disable_thread_safety(), and pwx::VElement::enable_thread_safety().

+ Here is the caller graph for this function:

◆ getSeed()

int32_t pwx::CRandom::getSeed ( ) const
noexcept

return current seed

This method simply returns the current Seed used to manipulate values to calculate Simplex Noise and random names.

Returns
Current Seed

◆ hash() [1/11]

uint32_t pwx::CRandom::hash ( int16_t  key) const
noexcept

hash an unsigned 16 bit integer to an unsigned 32 bit integer

Parameters
[in]keyThe key to hash
Returns
unsigned 32 bit integer hash

◆ hash() [2/11]

uint32_t pwx::CRandom::hash ( uint16_t  key) const
noexcept

hash a signed 16 bit integer to an unsigned 32 bit integer

Parameters
[in]keyThe key to hash
Returns
unsigned 32 bit integer hash

◆ hash() [3/11]

uint32_t pwx::CRandom::hash ( int32_t  key) const
noexcept

hash a signed 32 bit integer to an unsigned 32 bit integer

Parameters
[in]keyThe key to hash
Returns
unsigned 32 bit integer hash

◆ hash() [4/11]

uint32_t pwx::CRandom::hash ( uint32_t  key) const
noexcept

hash an unsigned 32 bit integer to an unsigned 32 bit integer

Parameters
[in]keyThe key to hash
Returns
unsigned 32 bit integer hash

◆ hash() [5/11]

uint32_t pwx::CRandom::hash ( int64_t  key) const
noexcept

hash a signed 64 bit integer to an unsigned 32 bit integer

Parameters
[in]keyThe key to hash
Returns
unsigned 32 bit integer hash

◆ hash() [6/11]

uint32_t pwx::CRandom::hash ( uint64_t  key) const
noexcept

hash an unsigned 64 bit integer to an unsigned 32 bit integer

Parameters
[in]keyThe key to hash
Returns
unsigned 32 bit integer hash

◆ hash() [7/11]

uint32_t pwx::CRandom::hash ( float  key) const
noexcept

hash float to an unsigned 32 bit integer

Parameters
[in]keyThe key to hash
Returns
unsigned 32 bit integer hash

◆ hash() [8/11]

uint32_t pwx::CRandom::hash ( double  key) const
noexcept

hash double to an unsigned 32 bit integer

Parameters
[in]keyThe key to hash
Returns
unsigned 32 bit integer hash

◆ hash() [9/11]

uint32_t pwx::CRandom::hash ( long double  key) const
noexcept

hash long double to an unsigned 32 bit integer

Parameters
[in]keyThe key to hash
Returns
unsigned 32 bit integer hash

◆ hash() [10/11]

uint32_t pwx::CRandom::hash ( const char *  key,
size_t  keyLen = 0 
) const
noexcept

hash C-String to an unsigned 32 bit integer

Parameters
[in]keyThe key to hash
[in]keyLenif omitted, a 0-terminated C-String is assumed
Returns
unsigned 32 bit integer hash

◆ hash() [11/11]

uint32_t pwx::CRandom::hash ( std::string &  key) const
noexcept

hash an std::string to an unsigned 32 bit integer

Parameters
[in]keyThe key to hash
Returns
unsigned 32 bit integer hash

◆ is_locked()

bool pwx::CLockable::is_locked ( ) const
noexceptinherited

return true if this object is locked

return true if this object is currently locked

References pwx::CLockable::memOrdLoad.

◆ is_locking()

bool pwx::CLockable::is_locking ( ) const
noexceptinherited

true if thread safety is turned on

return true if the locking is turned on.

◆ lock()

void pwx::CLockable::lock ( )
noexceptinherited

lock this object

lock

Lock this object for the current thread if locking is enabled.

References CURRENT_THREAD_ID, pwx::CLockable::isDestroyed, and pwx::CLockable::memOrdLoad.

Referenced by pwx::private_::CThreadElementStore::curr().

+ Here is the caller graph for this function:

◆ lock_count()

uint32_t pwx::CLockable::lock_count ( ) const
noexceptinherited

number of locks this thread holds on this object

return the number of locks on this object this thread has

Returns
the number of current locks held by the calling thread

References CURRENT_THREAD_ID.

◆ nextNST()

eNameSourceType pwx::CRandom::nextNST ( void  )
noexcept

Switches to the next [N]ame[S]ource[T]ype and returns that.

Returns
The next NST or the first, if the last was already set.

◆ noise() [1/4]

double pwx::CRandom::noise ( int32_t  x) const
noexcept

noise with one dimension

This method calculates a noise value between -1.0 and 1.0 out of one integer

Parameters
[in]xparamter to transform
Returns
double noise value between -1.0 and +1.0

◆ noise() [2/4]

double pwx::CRandom::noise ( int32_t  x,
int32_t  y 
) const
noexcept

noise with two dimensions

This method calculates a noise value between -1.0 and 1.0 out of two integers

Parameters
[in]xparamter to transform
[in]yparamter to transform
Returns
double noise value between -1.0 and +1.0

References pwx::constants::fullMaxInt.

◆ noise() [3/4]

double pwx::CRandom::noise ( int32_t  x,
int32_t  y,
int32_t  z 
) const
noexcept

noise with three dimensions

This method calculates a noise value between -1.0 and 1.0 out of three integers

Parameters
[in]xparamter to transform
[in]yparamter to transform
[in]zparamter to transform
Returns
double noise value between -1.0 and +1.0

References pwx::constants::fullMaxInt.

◆ noise() [4/4]

double pwx::CRandom::noise ( int32_t  x,
int32_t  y,
int32_t  z,
int32_t  w 
) const
noexcept

noise with four dimensions

This method calculates a noise value between -1.0 and 1.0 out of four integers

Parameters
[in]xparamter to transform
[in]yparamter to transform
[in]zparamter to transform
[in]wparamter to transform
Returns
double noise value between -1.0 and +1.0

◆ prevNST()

eNameSourceType pwx::CRandom::prevNST ( void  )
noexcept

Switches to the previous [N]ame[S]ource[T]ype and returns that.

Returns
The previous NST or the last, if the first was already set.

◆ random() [1/19]

int16_t pwx::CRandom::random ( int16_t  max)
noexcept

Generate a random value of int16_t between 0 and max.

if a negative max is submitted, the result will be max <= result <= 0.

Parameters
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [2/19]

int16_t pwx::CRandom::random ( int16_t  min,
int16_t  max 
)
noexcept

Generate a random value of int16_t between min and max.

if max is lower than min, the result will be max <= result <= min.

Parameters
[in]minMinimum result.
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [3/19]

uint16_t pwx::CRandom::random ( uint16_t  max)
noexcept

Generate a random value of uint16_t between 0 and max.

if a negative max is submitted, the result will be max <= result <= 0.

Parameters
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [4/19]

uint16_t pwx::CRandom::random ( uint16_t  min,
uint16_t  max 
)
noexcept

Generate a random value of uint16_t between min and max.

if max is lower than min, the result will be max <= result <= min.

Parameters
[in]minMinimum result.
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [5/19]

int32_t pwx::CRandom::random ( int32_t  max = RAND_MAX)
noexcept

Generate a random value of int32_t between 0 and max.

if a negative max is submitted, the result will be max <= result <= 0.

Parameters
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [6/19]

int32_t pwx::CRandom::random ( int32_t  min,
int32_t  max 
)
noexcept

Generate a random value of int32_t between min and max.

if max is lower than min, the result will be max <= result <= min.

This method has a default value of RAND_MAX for max.

Parameters
[in]minMinimum result.
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [7/19]

uint32_t pwx::CRandom::random ( uint32_t  max = RAND_MAX)
noexcept

Generate a random value of uint32_t between 0 and max.

if a negative max is submitted, the result will be max <= result <= 0.

This method has a default value of RAND_MAX for max.

Parameters
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [8/19]

uint32_t pwx::CRandom::random ( uint32_t  min,
uint32_t  max 
)
noexcept

Generate a random value of uint32_t between min and max.

if max is lower than min, the result will be max <= result <= min.

Parameters
[in]minMinimum result.
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [9/19]

int64_t pwx::CRandom::random ( int64_t  max)
noexcept

Generate a random value of int64_t between 0 and max.

if a negative max is submitted, the result will be max <= result <= 0.

Parameters
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [10/19]

int64_t pwx::CRandom::random ( int64_t  min,
int64_t  max 
)
noexcept

Generate a random value of int64_t between min and max.

if max is lower than min, the result will be max <= result <= min.

Parameters
[in]minMinimum result.
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [11/19]

uint64_t pwx::CRandom::random ( uint64_t  max)
noexcept

Generate a random value of uint64_t between 0 and max.

if a negative max is submitted, the result will be max <= result <= 0.

Parameters
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [12/19]

uint64_t pwx::CRandom::random ( uint64_t  min,
uint64_t  max 
)
noexcept

Generate a random value of uint64_t between min and max.

if max is lower than min, the result will be max <= result <= min.

Parameters
[in]minMinimum result.
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [13/19]

float pwx::CRandom::random ( float  max)
noexcept

Generate a random value of float between 0 and max.

if a negative max is submitted, the result will be max <= result <= 0.

Parameters
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [14/19]

float pwx::CRandom::random ( float  min,
float  max 
)
noexcept

Generate a random value of float between min and max.

if max is lower than min, the result will be max <= result <= min.

Parameters
[in]minMinimum result.
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [15/19]

double pwx::CRandom::random ( double  max)
noexcept

Generate a random value of double between 0 and max.

if a negative max is submitted, the result will be max <= result <= 0.

Parameters
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [16/19]

double pwx::CRandom::random ( double  min,
double  max 
)
noexcept

Generate a random value of double between min and max.

if max is lower than min, the result will be max <= result <= min.

Parameters
[in]minMinimum result.
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [17/19]

long double pwx::CRandom::random ( long double  max)
noexcept

Generate a random value of long double between 0 and max.

if a negative max is submitted, the result will be max <= result <= 0.

Parameters
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [18/19]

long double pwx::CRandom::random ( long double  min,
long double  max 
)
noexcept

Generate a random value of long double between min and max.

if max is lower than min, the result will be max <= result <= min.

Parameters
[in]minMinimum result.
[in]maxMaximum result.
Returns
A random value between 0 and max.

◆ random() [19/19]

size_t pwx::CRandom::random ( char *  dest,
size_t  minLen,
size_t  maxLen 
)
noexcept

Generates a random C-String with minLen to maxLen characters.

The characters are in the range of a-z and A-Z. No whitespace or special characters are used.

Note: dest is not checked. It must have a size of at least maxLen + 1 zero-byte. This means, that if both values are 0, nothing is done with dest, and if the larger value is 1, dest will simply made to start with a zero-byte.

Parameters
[out]destthe char buffer the random character sequence is written into.
[in]minLenminimum length of the random character sequence.
[out]maxLenmaximum length of the random character sequence.
Returns
number of characters actually written including the final zero-byte.

◆ rndName() [1/8]

char * pwx::CRandom::rndName ( double  x,
bool  lN = false,
bool  mW = false 
)
noexcept

get random name (1D)

This is a convenient wrapper for getting a random name out of one dimension and switches for long name and multi part.

lN decides upon the maximum number of chars and syllables generated. A value of false (the default) results in a maximum of 12 chars in four syllables. Setting this argument to true results in a maximum of 20 chars in up to six syllables.

mW decides upon the maximum number of parts. A value of false (the default) produces a name out of one part. A value of true results in a name that can be generated out of up to three parts.

See also
char * CRandom::rndName(double x, double y, double z, double w, int32_t chars, int32_t sylls, int32_t parts) for documentation
Parameters
[in]xsimple number to influence the result.
[in]lNlongName - sets syllables to 3-8 and max chars to 28
[in]mWmultiWord - allows the name to contain spaces (0-2)
Returns
a malloc'd C-string with the name (WARNING: You have to free it after use!)

◆ rndName() [2/8]

char * pwx::CRandom::rndName ( double  x,
double  y,
bool  lN = false,
bool  mW = false 
)
noexcept

get random name (2D)

This is a convenient wrapper for getting a random name out of two dimensions and switches for long name and multi part.

lN decides upon the maximum number of chars and syllables generated. A value of false (the default) results in a maximum of 12 chars in four syllables. Setting this argument to true results in a maximum of 20 chars in up to six syllables.

mW decides upon the maximum number of parts. A value of false (the default) produces a name out of one part. A value of true results in a name that can be generated out of up to three parts.

See also
CRandom::rndName(double x, double y, double z, double w, bool lN, bool mW) for documentation
Parameters
[in]xsimple number to influence the result.
[in]ysimple number to influence the result.
[in]lNlongName - sets syllables to 3-8 and max chars to 28
[in]mWmultiWord - allows the name to contain spaces (0-2)
Returns
a malloc'd C-string with the name (WARNING: You have to free it after use!)

◆ rndName() [3/8]

char * pwx::CRandom::rndName ( double  x,
double  y,
double  z,
bool  lN = false,
bool  mW = false 
)
noexcept

get random name (3D)

This is a convenient wrapper for getting a random name out of three dimensions and switches for long name and multi part.

lN decides upon the maximum number of chars and syllables generated. A value of false (the default) results in a maximum of 12 chars in four syllables. Setting this argument to true results in a maximum of 20 chars in up to six syllables.

mW decides upon the maximum number of parts. A value of false (the default) produces a name out of one part. A value of true results in a name that can be generated out of up to three parts.

See also
CRandom::rndName(double x, double y, double z, double w, bool lN, bool mW) for documentation
Parameters
[in]xsimple number to influence the result.
[in]ysimple number to influence the result.
[in]zsimple number to influence the result.
[in]lNlongName - sets syllables to 3-8 and max chars to 28
[in]mWmultiWord - allows the name to contain spaces (0-2)
Returns
a malloc'd C-string with the name (WARNING: You have to free it after use!)

◆ rndName() [4/8]

char * pwx::CRandom::rndName ( double  x,
double  y,
double  z,
double  w,
bool  lN = false,
bool  mW = false 
)
noexcept

get random name (4D)

This is a convenient wrapper for getting a random name out of four dimensions and switches for long name and multi part.

lN decides upon the maximum number of chars and syllables generated. A value of false (the default) results in a maximum of 12 chars in four syllables. Setting this argument to true results in a maximum of 20 chars in up to six syllables.

mW decides upon the maximum number of parts. A value of false (the default) produces a name out of one part. A value of true results in a name that can be generated out of up to three parts.

See also
CRandom::rndName(double x, double y, double z, double w, bool lN, bool mW) for documentation
Parameters
[in]xsimple number to influence the result.
[in]ysimple number to influence the result.
[in]zsimple number to influence the result.
[in]wsimple number to influence the result.
[in]lNlongName - sets syllables to 3-8 and max chars to 28
[in]mWmultiWord - allows the name to contain spaces (0-2)
Returns
a malloc'd C-string with the name (WARNING: You have to free it after use!)

◆ rndName() [5/8]

char * pwx::CRandom::rndName ( double  x,
int32_t  chars,
int32_t  sylls,
int32_t  parts 
)
noexcept

get random name (1D)

This is a convenient wrapper for getting a random name out of one dimension.

See also
char * CRandom::rndName(double x, double y, double z, double w, int32_t chars, int32_t sylls, int32_t parts) for documentation
Parameters
[in]xsimple number to influence the result.
[in]charsset the maximum number of characters to be generated
[in]syllsset the maximum number of syllables to be generated
[in]partsset the maximum number of parts the resulting name consists of
Returns
a malloc'd C-string with the name (WARNING: You have to free it after use!)

◆ rndName() [6/8]

char * pwx::CRandom::rndName ( double  x,
double  y,
int32_t  chars,
int32_t  sylls,
int32_t  parts 
)
noexcept

get random name (2D)

This is a convenient wrapper for getting a random name out of two dimensions.

See also
char * CRandom::rndName(double x, double y, double z, double w, int32_t chars, int32_t sylls, int32_t parts) for documentation
Parameters
[in]xsimple number to influence the result.
[in]ysimple number to influence the result.
[in]charsset the maximum number of characters to be generated
[in]syllsset the maximum number of syllables to be generated
[in]partsset the maximum number of parts the resulting name consists of
Returns
a malloc'd C-string with the name (WARNING: You have to free it after use!)

◆ rndName() [7/8]

char * pwx::CRandom::rndName ( double  x,
double  y,
double  z,
int32_t  chars,
int32_t  sylls,
int32_t  parts 
)
noexcept

get random name (3D)

This is a convenient wrapper for getting a random name out of three dimensions.

See also
char * CRandom::rndName(double x, double y, double z, double w, int32_t chars, int32_t sylls, int32_t parts) for documentation
Parameters
[in]xsimple number to influence the result.
[in]ysimple number to influence the result.
[in]zsimple number to influence the result.
[in]charsset the maximum number of characters to be generated
[in]syllsset the maximum number of syllables to be generated
[in]partsset the maximum number of parts the resulting name consists of
Returns
a malloc'd C-string with the name (WARNING: You have to free it after use!)

◆ rndName() [8/8]

char * pwx::CRandom::rndName ( double  x,
double  y,
double  z,
double  w,
int32_t  chars,
int32_t  sylls,
int32_t  parts 
)
noexcept

get random name

This method produces random names by combining letters into syllables and syllables into words. This strictly depends on pseudo random generators, utilizing noise() and simplex() methods. Therefore you get the same result if called twice with the same seed set and arguments set.

The main switch for the name generation is parts, which must be at least one. Each parts consits of at least two syllables. Therefore, if you set sylls to a lower value than parts + 1, sylls will be raised automatically. Furthermore each syllable consist of two to four chars. Thus if you set chars to a lower value than (sylls * 3) + 2, it will be raised, too. In the end chars will be at least: 3 * (1 + parts) + 2.

You can use one of the convenient wrapper which let you decide whether you want long or short names, consisting of one or up to three parts.

Parameters
[in]xsimple number to influence the result.
[in]ysimple number to influence the result.
[in]zsimple number to influence the result.
[in]wsimple number to influence the result.
[in]charsset the maximum number of characters to be generated
[in]syllsset the maximum number of syllables to be generated
[in]partsset the maximum number of parts the resulting name consists of
Returns
a malloc'd C-string with the name (WARNING: You have to free it after use!)

1) Determine whether the next syllable ends a part, genSyllable() needs to know.

2) generate syllable:

3) if we have a syllable (genSyllable produces an empty string on error) it can be added:

◆ setNST()

void pwx::CRandom::setNST ( eNameSourceType  type)
noexcept

set name source type to type

Parameters
[in]typethe new name source type

◆ setSeed()

void pwx::CRandom::setSeed ( int32_t  newSeed)
noexcept

set Simplex Seed

Set the seed to newSeed which will cause the simplex table to be reinitialized.

◆ simplex1D() [1/2]

double pwx::CRandom::simplex1D ( double  x,
double  zoom = 1.0,
double  smooth = 1.0 
)
noexcept

calculate a one dimensional simplex noise value

This method returns a simplex noise value of one dimension.

  • zoom and smooth have a default value of 1.
  • zoom has a minimum of 0.001, as a thounsandth produces very high values already and zoom must not be zero.
  • smooth has a minimum value of 1.0 to make sure the [-1, 1] intervall isn't broken.
    Parameters
    [in]xX-Coordinate of the Simplex Point, modified by the simplex seed.
    [in]zoomZooming factor into the point. Your coordinate will divided by this factor.
    [in]smoothDivisor for the result. The higher, the nearer the result will be to zero.

◆ simplex1D() [2/2]

double pwx::CRandom::simplex1D ( double  x,
double  zoom,
double  smooth,
double  reduction,
int32_t  waves 
)
noexcept

calculate a one dimensional simplex wave

This method returns a simplex wave of one dimension. The number of waves specified will overlay each others with multiplied smoothing, specified by 'reduction'. The default value of 1 wave just returns the simplex noise value in an intervall of [-1, 1]. While having more than one waves makes it possible to stay in this intervall, the results will most probably be nearer to zero.

  • zoom has a minimum of 0.001, as a thounsandth produces very high values already and zoom must not be zero.
  • smooth has a minimum value of 1.0 to make sure the [-1, 1] intervall isn't broken.
  • reduction has a minimum value of 1.0 to ensure the savety of the resulting intervall.
  • waves has a minimum value of 1.
Parameters
[in]xX-Coordinate of the Simplex Point, modified by the simplex seed.
[in]zoomZooming factor into the point. Your coordinate will divided by this factor.
[in]smoothDivisor for the result. The higher, the nearer the result will be to zero.
[in]reductionMultiplier for the smoothing factor in each round.
[in]wavesNumber of waves to overlay. The default of 1 returns the pure Simplex Noise Value.

◆ simplex2D() [1/2]

double pwx::CRandom::simplex2D ( double  x,
double  y,
double  zoom = 1.0,
double  smooth = 1.0 
)
noexcept

calculate a two dimensional simplex noise value

This method returns a simplex noise value of two dimensions.

  • zoom and smooth have a default value of 1.
  • zoom has a minimum of 0.001, as a thounsandth produces very high values already and zoom must not be zero.
  • smooth has a minimum value of 1.0 to make sure the [-1, 1] intervall isn't broken.
Parameters
[in]xX-Coordinate of the Simplex Point, modified by the simplex seed.
[in]yY-Coordinate of the Simplex Point, modified by the simplex seed.
[in]zoomZooming factor into the point. Your coordinate will divided by this factor.
[in]smoothDivisor for the result. The higher, the nearer the result will be to zero.

◆ simplex2D() [2/2]

double pwx::CRandom::simplex2D ( double  x,
double  y,
double  zoom,
double  smooth,
double  reduction,
int32_t  waves 
)
noexcept

calculate a two dimensional simplex wave

This method returns a simplex wave of two dimensions. The number of waves specified will overlay each others with multiplied smoothing, specified by 'reduction'. The default value of 1 wave just returns the simplex noise value in an intervall of [-1, 1]. While having more than one waves makes it possible to stay in this intervall, the results will most probably be nearer to zero.

  • zoom has a minimum of 0.001, as a thounsandth produces very high values already and zoom must not be zero.
  • smooth has a minimum value of 1.0 to make sure the [-1, 1] intervall isn't broken.
  • reduction has a minimum value of 1.0 to ensure the savety of the resulting intervall.
  • waves has a minimum value of 1.
Parameters
[in]xX-Coordinate of the Simplex Point, modified by the simplex seed.
[in]yY-Coordinate of the Simplex Point, modified by the simplex seed.
[in]zoomZooming factor into the point. Your coordinate will divided by this factor.
[in]smoothDivisor for the result. The higher, the nearer the result will be to zero.
[in]reductionMultiplier for the smoothing factor in each round.
[in]wavesNumber of waves to overlay. The default of 1 returns the pure Simplex Noise Value.

◆ simplex3D() [1/2]

double pwx::CRandom::simplex3D ( double  x,
double  y,
double  z,
double  zoom = 1.0,
double  smooth = 1.0 
)
noexcept

calculate a three dimensional simplex noise value

This method returns a simplex wave of three dimensions.

  • zoom and smooth have a default value of 1.
  • zoom has a minimum of 0.001, as a thounsandth produces very high values already and zoom must not be zero.
  • smooth has a minimum value of 1.0 to make sure the [-1, 1] intervall isn't broken.
Parameters
[in]xX-Coordinate of the Simplex Point, modified by the simplex seed.
[in]yY-Coordinate of the Simplex Point, modified by the simplex seed.
[in]zZ-Coordinate of the Simplex Point, modified by the simplex seed.
[in]zoomZooming factor into the point. Your coordinate will divided by this factor.
[in]smoothDivisor for the result. The higher, the nearer the result will be to zero.

◆ simplex3D() [2/2]

double pwx::CRandom::simplex3D ( double  x,
double  y,
double  z,
double  zoom,
double  smooth,
double  reduction,
int32_t  waves 
)
noexcept

calculate a three dimensional simplex wave

This method returns a simplex wave of three dimensions. The number of waves specified will overlay each others with reduced zoom, specified by 'reduction'. The default value of 1 wave just returns the simplex noise value in an intervall of [-1, 1]. While having more than one waves makes it possible to stay in this intervall, the results will most probably be nearer to zero.

  • zoom has a minimum of 0.001, as a thounsandth produces very high values already and zoom must not be zero.
  • smooth has a minimum value of 1.0 to make sure the [-1, 1] intervall isn't broken.
  • reduction has a minimum value of 1.0 to ensure the savety of the resulting intervall.
  • waves has a minimum value of 1.
Parameters
[in]xX-Coordinate of the Simplex Point, modified by the simplex seed.
[in]yY-Coordinate of the Simplex Point, modified by the simplex seed.
[in]zZ-Coordinate of the Simplex Point, modified by the simplex seed.
[in]zoomZooming factor into the point. Your coordinate will divided by this factor.
[in]smoothDivisor for the result. The higher, the nearer the result will be to zero.
[in]reductionMultiplier for the smoothing factor in each round.
[in]wavesNumber of waves to overlay. The default of 1 returns the pure Simplex Noise Value.

◆ simplex4D() [1/2]

double pwx::CRandom::simplex4D ( double  x,
double  y,
double  z,
double  w,
double  zoom = 1.0,
double  smooth = 1.0 
)
noexcept

calculate a four dimensional simplex noise value

This method returns a simplex noise value of four dimension.

  • zoom and smooth have a default value of 1.
  • zoom has a minimum of 0.001, as a thounsandth produces very high values already and zoom must not be zero.
  • smooth has a minimum value of 1.0 to make sure the [-1, 1] intervall isn't broken.
Parameters
[in]xX-Coordinate of the Simplex Point, modified by the simplex seed.
[in]yY-Coordinate of the Simplex Point, modified by the simplex seed.
[in]zZ-Coordinate of the Simplex Point, modified by the simplex seed.
[in]wW-Coordinate of the Simplex Point, modified by the simplex seed.
[in]zoomZooming factor into the point. Your coordinate will divided by this factor.
[in]smoothDivisor for the result. The higher, the nearer the result will be to zero.

◆ simplex4D() [2/2]

double pwx::CRandom::simplex4D ( double  x,
double  y,
double  z,
double  w,
double  zoom,
double  smooth,
double  reduction,
int32_t  waves 
)
noexcept

calculate a four dimensional simplex wave

This method returns a simplex wave of four dimension. The number of waves specified will overlay each others with reduced zoom, specified by 'reduction'. The default value of 1 wave just returns the simplex noise value in an intervall of [-1, 1]. While having more than one waves makes it possible to stay in this intervall, the results will most probably be nearer to zero.

  • zoom, smooth, reduction and waves all have a default value of 1.
  • zoom has a minimum of 0.001, as a thounsandth produces very high values already and zoom must not be zero.
  • smooth has a minimum value of 1.0 to make sure the [-1, 1] intervall isn't broken.
  • reduction has a minimum value of 1.0 to ensure the savety of the resulting intervall.
  • waves has a minimum value of 1.
Parameters
[in]xX-Coordinate of the Simplex Point, modified by the simplex seed.
[in]yY-Coordinate of the Simplex Point, modified by the simplex seed.
[in]zZ-Coordinate of the Simplex Point, modified by the simplex seed.
[in]wW-Coordinate of the Simplex Point, modified by the simplex seed.
[in]zoomZooming factor into the point. Your coordinate will divided by this factor.
[in]smoothDivisor for the result. The higher, the nearer the result will be to zero.
[in]reductionMultiplier for the smoothing factor in each round.
[in]wavesNumber of waves to overlay. The default of 1 returns the pure Simplex Noise Value.

◆ try_lock()

bool pwx::CLockable::try_lock ( )
noexceptinherited

try to lock and return at once

try_lock

Try to lock this object.

Returns
true if the object could be locked, false otherwise.

References CURRENT_THREAD_ID, pwx::CLockable::isDestroyed, and pwx::CLockable::memOrdLoad.

Referenced by pwx::try_locks().

+ Here is the caller graph for this function:

◆ unlock()

void pwx::CLockable::unlock ( )
noexceptinherited

unlock this object

unlock

If locking is disabled or if the current thread does not hold the lock, nothing happens. Otherwise the last lock is released.

References CURRENT_THREAD_ID.

Referenced by pwx::private_::CThreadElementStore::curr(), pwx::try_locks(), and pwx::unlock_all().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: