Oh man, can anybody help me get a working version of the mersenne twister going? i have tried about three or four different implementations now, including direct c++ ports of the original C and versions in C all kinds, i can run all the samples supplied with these implementations and see lots of stacks of floating point numbers, but i CANNOT get any of them to do what you want, ie give me a whole number from range n to n and SEED the blasted thing so i get different output each time!
I tried the seed by array, seed with 0, seed with bloody sunflower seeds, i just get same output every time.
Can somebody describe how to use the major seed functions that you see with the Mersenne twister?
You can just initialize the array with a simple lcg algo or something similar, which you seed with the seed intended for the mersenne twister.
You generate a number in a certain range with mersenne_rand()%(max-min+1)+min;
#include <stdio.h>
#define M 2147483647
#define A 16807
#define Q ( M / A )
#define R ( M % A )
staticint seed = 1;
int jsw_rand ( void )
{
seed = A * ( seed % Q ) - R * ( seed / Q );
if ( seed <= 0 )
seed += M;
return seed;
}
int main ( void )
{
int i;
for ( i = 0; i < 10; i++ )
printf ( "%d ", jsw_rand() );
printf ( "...\n" );
return 0;
}
Then i put this into my chosen function from the mersenne twister..
How do i get a common garden variety integer returned?, casting? the only thing these functions seem to deal in is long unsigned ints and what have you
EDIT: The value returned from this function is the same every time, so how is that of any use?
Do not use #define where not necessary.
If you're using the same seed every time, you'll obviously get the same number sequence each time.
Use something that constantly changes as a seed, i.e. time(0).