Re: Random number generators (was: RE: [AD] Allegro 4.2 todos)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> 1. Each example will define a different RNG algorithm. That way, we
> can show
> the users a series of different RNGs.
> 2. Include the 'alrand' lib with the distribution. This is not part
> of
> Allegro, but we could include it as an example of what an
> Allegro-addon
> should look like and how to use one. That way, each example that uses
> random
> numbers could use alrand.

Pardon me for saying so, but this sounds excessive.  Unless...  If
someone were to write a public rand_ex() function, and a
set_rand_type() function (which assigns a different RNG function
pointer to rand_ex()), I could see it working.  Then the examples would
be good, because they'd show variations on basic allegro functionality,
as the current example crop does.  As well, the random numbers would be
like the examples: basically identical across all platforms.

> Why not Elias' solution
>
>     (rand()>>8)+(rand()&0xff00)
>
> wrapped up in a macro and with a comment exposing the rationale?

I don't see why this would be an issue.  I also think that allegro
developers would benefit from having better randomness available, as
either a public macro or public function.

The issue is, though, that the above would need to be tested on
non-gcc-based build systems.  (Hell, at this point I'm curious to see
if there's a difference between gcc compilers on different
architectures.)  Personally I've always found rand(), using
srand(time(NULL)), to produce sufficiently random data for anything
I've wanted to do, but if one's picky enough to want better randomness
than that, they should also be picky enough to think about what kind of
numbers the above macro would work in Watcom or MSVC.

Now, since one of Allegro's big features is out-of-the-box portability
of programs written using it across so many platforms, I would think
that having a public allegro_random() or rand_ex() function would go
towards making a port homogeneous, as the same random numbers could be
gotten on all platforms and all compilers.

- Charles




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/