Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

dumb questions: seeding Tausworthe generator

Name: derp 2010-03-22 16:20

I'm not even sure if this code is right because I've only been able to find a couple snippets about the Tausworthe Generator on Google, neither of which were actually working implementations.

#include <stdio.h>
#include <time.h>
int s1, s2, s3;

int taus_gen(void) {
        s1 = ( (s1 & 0xFFFFFFFE) << 12) ^ (( (s1 << 13) ^ s1) >> 19);
        s2 = ( (s2 & 0xFFFFFFF8) << 4) ^ (( (s2 << 2) ^ s2) >> 25);
        s3 = ( (s3 & 0xFFFFFFF0) << 17) ^ (( (s3 << 3) ^ s3) >> 11);
        return s1 ^ s2 ^ s3;
}

int main(void) {
        int i;
        s1 = time(NULL);
        s2 = time(NULL);
        s3 = time(NULL);
       
        for (i=0;  i < 10;  i++)
                printf("%i\n", taus_gen());

        return 0;
}


1. Is this code a correct implementation of a Tausworthe generator?

2. Is simply using the time, ie. through time(), the best way to seed the three state variables?

I am now noticing there there's a visible pattern to the numbers that I output from one run to the next...
2575887790
2366031142
4046607044

2575879598
2399585702
4047131270

2578000942
2433154598
3108229496

Perhaps I am doing it wrong...

Name: Anonymous 2010-03-22 18:01

>>4

Oh, and to be precise, I think the value of time changes once every second.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List