while (1)
{
Std.srand(1200); //set your seed
for(0 => int i; i < 8; i++)
{
<<<Std.rand2( 1 , 1000 )>>>;
}
<<<"--------------", "we always get the same numbers" >>>;
2::second=>now;
}
But this won't work if you use the randomizer elsewhere in your code. if someone calls Std.rand2() before the loop above has finished, the random sequence will be corrupted. It will work here though, since there is no wait statement inside the for loop, but I suspect Lars's code is more complicated than this.
Other programming languages will usually have some kind of randomizer object (e.g. "Random" in Java or the result of the seed function in PovRAY), that you instantiate with a seed (if you want) and then use independent from other random instances. If we had that you could write this code:
0 => int resetSeed;
Std.makeRandomizer() => Random r;
while (1)
{
if (resetSeed) {
r.srand(1200); //set your seed
}
for(0 => int i; i < 8; i++)
{
<<<r.rand2( 1 , 1000 )>>>;
}
<<<"--------------", "we always get the same numbers" >>>;
2::second=>now;
}
...without clashing with other usage of randomizers (I made up some function and class names).
Was it something like this that you ran into, Lars?
/Stefan
2010/9/11 Kassen
<signal.automatique@gmail.com> Hey, Lars!
I'm not Stephan, but I'm still a bit confused as well so I thought I'd answer anyway.
Std.srand(1200); //set your seed
Looks fine
<<<"--------------", "we always get the same numbers" >>>;
That's what we'd expect, yes.
Well.... no, not really.
What happens if you don't set the seed with srand(), do you still get the same numbers? As I understand things now you should get exactly what you are looking for by simply not setting the seed in line 1. Could you verify that by not setting the seed at all you get different numbers each time you run your program? If not we have a bug. I seem to remember there was a issue like that on Windows, which might be caused by Windows (last time I looked) not having the "storage" of OS-event based random numbers that Unix typically uses; that might be the cause. That's no excuse though; as we are not trying to secure nuclear missiles (I hope!) something like the time in ms should yield a perfectly serviceable seed at VM startup.
Yours,
Kas.
_______________________________________________
chuck-users mailing list
chuck-users@lists.cs.princeton.edu
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
--
Release me, insect, or I will destroy the Cosmos!
_______________________________________________