Am Sat, 7 Jun 2014 12:19:11 +0300
schrieb Matti Nykyri <matti.nyk...@iki.fi>:

> On Sat, Jun 07, 2014 at 12:03:29AM +0300, Matti Nykyri wrote:
[...]
> unsigned char get_6bits () 
> {
>       static unsigned int rand = 0; //(sizeof(int) = 32)

Just an itty bitty nitpick: since you already require C99 as per the for loop
below, you might as well use uint32_t (from stdint.h) instead of assuming that
sizeof(int) == 32 :) .

>       static char bits_avail = 0;
>       unsigned char result = 0;
> 
>       //get 2 bits 3 times: 32 is devidable by 2
>       for (int i = 0; i < 3; i++) { // --std=c99
>               //Fill buffer if it is empty!
>               if (!bits_avail || bits_avail < 0 ) { //if bits_avail < 0 it is 
> an error!
>                       // Use the correct call for ISAAC instead of rand()
>                       rand = rand();
>                       
>                       bits_avail = 32;
>               }
> 
>               result <<= 2; //move two bits to left.
>               result = result | (rand & 0x3); //add two least signifigant 
> bits to the result.
>               rand >>= 2; //move two bits to right.
>               bits_avail -= 2;
>       }
> 
>       return result; //result has 6 bits of random data...
> }
> 
> char next_character()
> {
>       unsigned char idx = 0;
>       do {
>               idx = get_6bits();
>       } while (idx > 61);
> 
>       return S[idx];
> }
> 
> Very simple :)
[...]

-- 
Marc Joliet
--
"People who think they know everything really annoy those of us who know we
don't" - Bjarne Stroustrup

Attachment: signature.asc
Description: PGP signature

Reply via email to