mirror of https://github.com/OISF/suricata
Move rand seed code into util-random
parent
6224c30548
commit
6beee776ca
@ -0,0 +1,26 @@
|
||||
/** \file
|
||||
* \author Pablo Rincon <pablo.rincon.crespo@gmail.com>
|
||||
*/
|
||||
|
||||
#include "suricata-common.h"
|
||||
#include "detect.h"
|
||||
#include "threads.h"
|
||||
#include "util-debug.h"
|
||||
|
||||
/**
|
||||
* \brief create a seed number to pass to rand() , rand_r(), and similars
|
||||
* \retval seed for rand()
|
||||
*/
|
||||
unsigned int RandomTimePreseed(void) {
|
||||
/* preseed rand() */
|
||||
time_t now = time ( 0 );
|
||||
unsigned char *p = (unsigned char *)&now;
|
||||
unsigned seed = 0;
|
||||
size_t ind;
|
||||
|
||||
for ( ind = 0; ind < sizeof now; ind++ )
|
||||
seed = seed * ( UCHAR_MAX + 2U ) + p[ind];
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
#ifndef __UTIL_RANDOM_H__
|
||||
#define __UTIL_RANDOM_H__
|
||||
|
||||
unsigned int RandomTimePreseed(void);
|
||||
|
||||
#endif /* __UTIL_RANDOM_H__ */
|
||||
|
Loading…
Reference in New Issue