Boost logo

Boost Users :

Subject: Re: [Boost-users] Seeding boost::mt19937 with bytes from CryptoGenRandom
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2010-02-11 12:06:11


Steven,

I know at least 2 books which describe this possibility and there is nothing
stated about undefined behavior. I just double checked the ISO 2003 C++
Standards and did not find anything which disallows the presented approach.
Can you point me to the paragraph in the Standard?

Thanks,
Ovanes

>>
>> Seems, like I forgot the signature... Another way to transfer the bytes
>> would be:
>>
>> union bytes2seed
>> {
>> uint64_t seed_;
>> char bytes_[sizeof(uint64_t)];
>> };
>>
>> bytes2seed converter;
>>
>> Now one can pass &converter.bytes_[0] to CryptGenRandom. This does not
>> require an additional memcpy call.
>>
>>
>
> Casting through a union is undefined behavior. :(.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net