Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Implementing the KISS4691 RNG
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ben Bacarisse  
View profile  
 More options Sep 6 2010, 10:41 am
Newsgroups: sci.math, comp.lang.c, comp.lang.fortran
From: Ben Bacarisse <ben.use...@bsb.me.uk>
Date: Mon, 06 Sep 2010 15:41:07 +0100
Local: Mon, Sep 6 2010 10:41 am
Subject: Re: Implementing the KISS4691 RNG

Ian Collins <ian-n...@hotmail.com> writes:
> On 09/ 6/10 09:57 PM, robin wrote:
>> "Ian Collins"<ian-n...@hotmail.com>  wrote in message news:8ejqjaFhq7U6@mid.individual.net...

>> |>  It's for 32 bit words.
>> |>  As previously, for longer words, it's necessary to truncate.
>> |
>> | Then it shouldn't make assumptions about the sizes of types.  If fixed
>> | width types are required, use them.

>> You would need to truncate to 32 bits immediately after each right shift.

> As I said, use fixed size types.  Otherwise the code won't work in 64
> bit builds.

> #include <stdint.h>

> uint32_t MWC(void)
> {
>   uint32_t t,x;
>   static uint32_t c=0,j=4691;

>   j=(j<4690)? j+1:0;
>   x=Q[j];
>   t=(x<<13)+c;

>   if(t<c) {
>     c=(x>>19)+1;
>     t=t+x;
>   }
>   else {
>     t=t+x;
>     c=(x>>19)+(t<x);
>   }
>   return Q[j]=t;
> }

Just as a side note...  To increase portability one could use
uint_fast32_t and mask the result.  The mask will be optimised away (by
any decent compiler) when uint_fast32_t is actually a 32-bit type.

For maximum portability C90 has to be used, and there the simplest
option is to use unsigned long since int may not be 32 bits (unsigned
long must be at least that wide).  The mask is then needed.  In C90, I
think the only way to avoid using a type that is too wide is to use #ifs
to see if unsigned int will do.

--
Ben.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.