void rand_seed(uint seed, uint index)
|
Use this function to create a repeatable sequence of random numbers.
Seed is used to start the sequence, while index tells the function to begin with the index-th number. Incrementing index is the same as calling rand() one more time after rand_seed.
Note: The random number generator is seeded at program startup with a good number. There is no need to do that every time yourself.
Example:
import std.stdio;
import std.random;
void main()
{
const int max = 3;
writefln("Before rand_seed() called...");
for(int i = 1; i <= max; i++)
writefln("rand() is %12d", rand());
rand_seed(1,0);
writefln("\nAfter rand_seed(1,0) called...");
for(int i = 1; i <= max; i++)
writefln("rand() is %12d", rand());
rand_seed(1,1);
writefln("\nAfter rand_seed(1,1) called...");
for(int i = 1; i <= max; i++)
writefln("rand() is %12d", rand());
}
|
Output could be:
Before rand_seed() called...
rand() is 3504812646
rand() is 904386554
rand() is 373390471
After rand_seed(1,0) called...
rand() is 48551977
rand() is 1352404003
rand() is 370828309
After rand_seed(1,1) called...
rand() is 1352404003
rand() is 370828309
rand() is 1385419666 |
See also:
rand
|