MCPcopy Create free account
hub / github.com/carbonengine/trinity / RandCheap

Function RandCheap

trinity/Particle/Tr2ParticleSystem.h:145–159  ·  view source on GitHub ↗

---------------------------------------------------------------------------------- Description: A cheap thread-safe lock-free pseudo random number generator based on http://www.firstpr.com.au/dsp/rand31/ Return Value: Random integer between 0 and 2^31. ----------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

143 // Random integer between 0 and 2^31.
144 // ----------------------------------------------------------------------------------
145 static inline uint32_t RandCheap()
146 {
147 static CcpAtomic<uint32_t> globalSeed( rand() );
148 // We increment global seed here so that if two threads get to this point
149 // simultaneously they would still get different results.
150 uint32_t seed = globalSeed;
151 uint32_t hi, lo;
152 lo = 16807 * ( seed & 0xffff );
153 hi = 16807 * ( seed >> 16 );
154 lo += ( hi & 0x7fff ) << 16;
155 lo += hi >> 15;
156 lo = ( lo & 0x7FFFFFFF ) + ( lo >> 31 );
157 globalSeed = static_cast<uint32_t>( lo );
158 return lo;
159 }
160
161 // ----------------------------------------------------------------------------------
162 // Description:

Callers 1

RandFloatFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected