Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: RNGs: A Super KISS
Replies: 14   Last Post: Feb 26, 2013 10:53 AM

 Messages: [ Previous | Next ]
 Dann Corbit Posts: 1,424 Registered: 12/8/04
Re: RNGs: A Super KISS
Posted: Nov 3, 2009 3:36 PM

On Nov 3, 12:23 pm, user923005 <dcor...@connx.com> wrote:
I copied and pasted from the wrong file. Here is the correct code
[snip]
class SuperKiss {

private:
unsigned long Q[41790];
unsigned long indx;
unsigned long carry;
unsigned long xcng;
unsigned long xs;

int refill ()
{
int i;
unsigned long long t;
for (i = 0; i < 41790; i++)
{
t = 7010176LL * Q[i] + carry;
carry = (t >> 32);
Q[i] = ~(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 long SKRand() {
return (indx < 41790 ? Q[indx++] : refill ()) +
(xcng = 69609 * xcng + 123) +
(xs ^= xs << 13, xs ^= (unsigned) xs >> 17, xs ^= xs >>
5);
}
};

int
main ()
{
unsigned long i;
int x=0;
SuperKiss sk;
for (i = 0; i < 1000000000; i++)
x = sk.SKRand();
std::cout << " x = " << x << std::endl << "Does x=-872412446?"
<< std::endl;
return 0;
}

Date Subject Author
11/3/09 geo
11/3/09 Dann Corbit
11/3/09 tom@iahu.ca
11/3/09 Dann Corbit