I need a good seed for an RNG

Apr 2, 2008 at 10:47pm
How do I get a good seed for a random number generator? I think I need a function similar to 'clock' in 'time.h', but it should return the number of clock ticks since the computer started, so it doesn't return the same number every time.
Apr 3, 2008 at 1:24am
add:
 
 #include <time.h>  


add:
 
 srand((unsigned)time(NULL)); 

(before you call rand();)
Apr 3, 2008 at 1:42am
That only generates a different seed every second. I need a function that changes the seed faster than that.
Apr 3, 2008 at 6:57am
I think the correct code is:
1
2
3
4
5
6
srand(unsigned(time(NULL)));
//then you should use an array where you assign the random values
long A[20];
for(int i=0;i<20;i++)
{A[i]=rand();
}

This should assign the vallues more faster.
Apr 3, 2008 at 6:15pm
I mean the seed, not the random numbers generated from it.
Apr 3, 2008 at 7:46pm
Is there a way you could manipulate your random results using a loop and math expressions for each second that the clock is seeding your generator?
That's the only thing I can think of trying, since I don't know how else to seed the generator.
Apr 3, 2008 at 7:46pm
Is there a way you could manipulate your random results using a loop and math expressions for each second that the clock is seeding your generator?
That's the only thing I can think of trying, since I don't know how else to seed the generator.
Apr 5, 2008 at 11:35am
try
1
2
3
4
5
6
7
int seed;
for(seed=1;;seed++);
{
srand(seed);
seed = rand();
printf("%d\n",seed);
}


hope it helps
Apr 6, 2008 at 8:44am
This is far better: http://xkcd.com/221/
Topic archived. No new replies allowed.