Re: [AD] Allegro 4.2 todos |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Angelo Mottola wrote:
I'd have posted the patch here anyway before commiting it this time :P
The current formula is:
((rand() >> 8) + (rand() & 0xff00))
As previously suggested on this list. I've found the following formula works
better under OSX though:
((rand() >> 16) + rand())
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.
I've tested other shift values between 8 and 16, but the best remains 16. So
I wonder: is this due to the machine endianess or just OSX rand()
implementation?
Since the meaning of arithmetic operations does not depend on
endianness, I think this has to be due to the implementation.
Sven