Facy random seed for qrand in kdelibs
Sebastian Trüg
trueg at kde.org
Mon Aug 2 16:42:14 BST 2010
On 08/02/2010 04:53 PM, George Kiagiadakis wrote:
> On Mon, Aug 2, 2010 at 5:52 PM, Sebastian Trüg <trueg at kde.org> wrote:
>> one of kdepim's Akonadi resources defines the method below to create a
>> proper random seed for qrand. IMHO we should put this in kdelibs
>> directly so all apps can benefit from it. Maybe KGlobal is the right
>> place for it?
>>
>> Any objections?
>>
>> Cheers,
>> Sebastian
>>
>> static void initRandomSeed()
>> {
>> static bool init = false;
>> if ( !init ) {
>> unsigned int seed;
>> init = true;
>> int fd = KDE_open( "/dev/urandom", O_RDONLY );
>> if ( fd < 0 || ::read( fd, &seed, sizeof( seed ) ) != sizeof( seed ) ) {
>> // No /dev/urandom... try something else.
>> srand( getpid() );
>> seed = rand() + time( 0 );
>> }
>>
>> if ( fd >= 0 )
>> close( fd );
>>
>> qsrand( seed );
>> }
>> }
>>
>
> This is the code from KRandom::random(), already in kdelibs.
that does not help me since I am using QUuid. :)
More information about the kde-core-devel
mailing list