Re: [AD] Allegro 4.2 todos |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
> It seems there are essentially four types of implementations:
>
> 1. 16-bit numbers, 8 lowest bits not very random.
> 2. 16-bit numbers, all bits random enough.
> 3. 32-bit numbers, 16 lowest bits not very random.
> 4. 32-bit numbers, all bits random enough.
>
> Either bits 8-15 or bits 16-31 are random enough with all these types of
> implementations. Thus, if we need 15 bit random numbers, the following
> might be worth trying:
>
> ((rand()>>16) ^ (rand()>>8) ^ rand()) & 0x7fff
>
> For type 1 and 2 implementations, the two last terms will give
> randomness, and for type 3 and 4 the first term will give randomness.
Hum... three calls to rand() seem a bit overkill.
Based on Sven's remark, I now think we shouldn't try to devise the
magic-formula-that-works-well-on-all-platforms but simply tailor it on a OS
basis.
Angelo, I think you could simply use whatever formula (which is guaranteed to
return a non-negative result though) fits your needs in alosxcfg.h and
define AL_RAND() to be simply rand() by default in alconfig.h .
--
Eric Botcazou