Re: Swapping is inefficient and wasteful

From: Ernst Lippe (ernstl-at-planet-dot-nl_at_ignore.this)
Date: 11/24/04


Date: Wed, 24 Nov 2004 12:38:54 +0100

On Tue, 23 Nov 2004 16:04:57 -0500, Brian Hetrick wrote:

> If one has cryptographically strong random byte source, as from an ARCFOUR
> implementation, a cryptographically strong U[0,1) rand () can be built
> trivially. Assuming arcfour () returns an integer value in [0,255], the
> expression:
>
> ((arcfour () / 256.0f + arcfour ()) / 256.0f + arcfour ()) / 256.0f
>
> gives a float uniformly distributed over [0,1).

That depends on the bitsize of your floats, in this way you
can get only 2**24 different output values, and when your
floats have a mantissa of more than 24 bits there are some
output values that your algorithm can't produce.

Ernst Lippe