On 4 nov, 22:51, Victor Bazarov <(E-Mail Removed)> wrote:

> user923005 wrote:

> [...]

>

> > #include <iostream>

>

> > class SuperKiss {

>

> > private:

> > * * unsigned int *Q[41790];

> > * * unsigned int *indx;

> > * * unsigned int *carry;

> > * * unsigned int *xcng;

> > * * unsigned int *xs;

>

> > * * int refill ()

> > * * {

> > * * * * int i;

> > * * * * unsigned long long t;

>

> BTW, currently there is no 'long long' in C++... *Although it is offered

> as an extension by some compilers.

>

> > * * * * for (i = 0; i < 41790; i++)

> > * * * * {

> > * * * * * * t = 7010176LL * Q[i] + carry;

>

> And neither is there the 'LL' suffix...

>

>

>

> > * * * * * * carry = (t >> 32);

> > * * * * * * Q[i] =(unsigned int) ~(t);

> > * * * * }

> > * * * * indx = 1;

> > * * * * return (Q[0]);

> > * * }

>

> > public:

> > * * // Constructor:

> > * * SuperKiss()

> > * * {

> > * * * * indx *= 41790;

> > * * * * carry = 362436;

> > * * * * xcng *= 1236789;

> > * * * * xs * *= 521288629;

> > * * * * unsigned i;

> > * * * * for (i = 0; i < 41790; i++)

> > * * * * * * Q[i] = (xcng = 69609 * xcng + 123) +

> > * * * * * * * * * *(xs ^= xs << 13, xs ^= (unsigned) xs >> 17, xs ^=

> > xs >> 5);

> > * * }

>

> > * * // Collect next random number:

> > * * unsigned int SKRand() {

> > * * * * return (indx < 41790 ? Q[indx++] : refill ()) +

> > * * * * * * * *(xcng = 69609 * xcng + 123) +

> > * * * * * * * *(xs ^= xs << 13, xs ^= (unsigned) xs >> 17, xs ^= xs >>

> > 5);

>

> There seems to be a common subexpression in two of those functions (ctor

> and 'SKRand'), I'd create a separate function for it.
And they rely on the same state, I would create a generator class but

I don't know if that would improve the speed.

struct SuperKissGenerator

{

unsigned long xcng;

unsigned long xs;

SuperKissGenerator()

cng(1236789),xs(521288629){}

unsigned long operator()()const

{

xcng = 69609 * xcng + 123;

xs ^= xs << 13;

xs ^= (unsigned) xs >> 17;

xs ^= xs >> 5;

return xcng + xs;

}

};

And then a member

SuperKissGenerator generator;

in constructor:

std::generate(Q,Q+41790,generator);

in SKRand:

return (indx < 41790 ? Q[indx++] : refill ()) + generator();

--

Michael