I need a good seed for an RNG

Nate879 (22)
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.
psault (133)
add:
 
 #include <time.h>  


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

(before you call rand();)
Nate879 (22)
That only generates a different seed every second. I need a function that changes the seed faster than that.
EWu (12)
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.
Nate879 (22)
I mean the seed, not the random numbers generated from it.
psault (133)
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.
psault (133)
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.
cyberpirate (38)
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
AzraelUK (57)
This is far better: http://xkcd.com/221/
Topic archived. No new replies allowed.