MCPcopy Create free account
hub / github.com/DFHack/dfhack / l_randomizePivot

Function l_randomizePivot

depends/lua/src/ltablib.c:258–268  ·  view source on GitHub ↗

** Use 'time' and 'clock' as sources of "randomness". Because we don't ** know the types 'clock_t' and 'time_t', we cannot cast them to ** anything without risking overflows. A safe way to use their values ** is to copy them to an array of a known type and use the array values. */

Source from the content-addressed store, hash-verified

256** is to copy them to an array of a known type and use the array values.
257*/
258static unsigned int l_randomizePivot (void) {
259 clock_t c = clock();
260 time_t t = time(NULL);
261 unsigned int buff[sof(c) + sof(t)];
262 unsigned int i, rnd = 0;
263 memcpy(buff, &c, sof(c) * sizeof(unsigned int));
264 memcpy(buff + sof(c), &t, sof(t) * sizeof(unsigned int));
265 for (i = 0; i < sof(buff); i++)
266 rnd += buff[i];
267 return rnd;
268}
269
270#endif /* } */
271

Callers 1

auxsortFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected