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;
I am now noticing there there's a visible pattern to the numbers that I output from one run to the next...
Just realized that this is probably completely irrelevant provided that the numbers are random when I use it to modulo against the upper bound of whatever I want, ie. int n = taus_gen() % 10 when I want 0..9.
Name:
Anonymous2010-03-22 16:24
s1, s2 and s3 are all seeded as more or less the same number.
The value that time(NULL) returns doesn't change immediately. If, for example, I were make a program that prints out the value of time(NULL), then repeats once (without a delay), it is likely that it will have printed the same number twice.
Basically, you're seeding the same values, over and over again. You need to incorporate some form of delay between your seeds.
Of course there's a pattern. It's a stateful generator. There's supposed to be a pattern. Furthermore, you fucked it up. It relies on the properties of unsigned integers. You need to make those ints unsigned ints.
>>7
In addendum, your second question can be answered by the second version of the Tausworthe seeding algorithm. Instead of raw bits, it uses the following:
Obviously SEPPLES, so you'll need to modify for C, but you should get the picture. The seeds can be anything you want, but I recommend using srand(time(0)); and then using three calls to rand() to get the seeds.
Name:
derp OP2010-03-22 20:17
Yeah, I know that I am essentially setting all 3 state variables to the same number. I'm just wondering whether the current time is an OK seed for this particular algorithm. I since talked to someone else who knows about this algorithm and they said I could use pretty much anything I want as long as I didn't use some really low values.
So as long as my code is correct, my question should be solved. :)
>>20
Wrong way round. TML.
I really need to get the balance right between the only two languages I both know and like, and Perl sure doesn't have typedef.