safelock.c
/* Generate a "unique" enough seed.
 *
 * Generate different random sequences using:
 * - getpid() for process separation
 * - stack address of "seed" for thread separation since each thread has
 *   a different location on the stack. Divide by 16 to handle 16 byte
 *   aligned variables. Many operating systems use Address Space Layout
 *   Randomization (ASLR) which greatly increases the effectiveness of
 *   using the stack address as a seed.
 * - The time is used to ensure the same thread receives a different
 *   sequence after each call to seed_init()
 */
Generate a "unique" enough seed.
Generate different random sequences using:
- getpid() for process separation
- stack address of "seed" for thread separation since each thread has
a different location on the stack. Divide by 16 to handle 16 byte
aligned variables. Many operating systems use Address Space Layout
Randomization (ASLR) which greatly increases the effectiveness of
using the stack address as a seed.
- The time is used to ensure the same thread receives a different
sequence after each call to seed_init()
Generate a " unique " enough seed . Generate different random sequences using : - getpid () for process separation - stack address of " seed " for thread separation since each thread has a different location on the stack . Divide by 16 to handle 16 byte aligned variables . Many operating systems use Address Space Layout Randomization ( ASLR ) which greatly increases the effectiveness of using the stack address as a seed . - The time is used to ensure the same thread receives a different sequence after each call to seed_init ()
static void seed_init(unsigned short seed[3])
{
    seed[0] = gettimeofday_us() % 0x10000;
    seed[1] = getpid() % 0x10000;
    seed[2] = ((unsigned long)seed / 16) % 0x10000;
}
static void seed_init ( unsigned short seed [ 3 ] ) { seed [ 0 ] = gettimeofday_us ( ) % 0x10000 ; seed [ 1 ] = getpid ( ) % 0x10000 ; seed [ 2 ] = ( ( unsigned long ) seed / 16 ) % 0x10000 ; }
Generate a "unique" enough seed.
Generate a " unique " enough seed .