[chuck-users] random seed

Lars Ullrich mail at larsullrich.de
Sat Sep 11 13:26:20 EDT 2010


> What happens if you don't set the seed with srand(), do you still  
> get the same numbers?

No.

> Could you verify that by not setting the seed at all you get  
> different numbers each time you run your program?


  I get different numbers. I think there is no bug, everything works  
like expected.. (for me)

  By the way, I've noticed that Std.srand dont like double integers..


> Was it something like this that you ran into, Lars?

mmm.. sorry Stefan, but I'm not sure what you mean? I was looking for  
a way to put off the seed and get to the normal "random mode".
Now I'm using a function Std.rand2(1,1000)=>int NewSeed and then I  
jump back to my stored seed, like in your code.


Lars





Am 11.09.2010 um 18:21 schrieb Stefan Blixt:

> Gotcha! Or at least, I can see a flaw here in ChucK's randomizers:  
> there is only one of them! My immediate reaction to seeing your code  
> was that it ought to be simplified to this:
>
> 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 at 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.
>
> Hope this helps!
>
>  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 at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
>
>
>
> -- 
> Release me, insect, or I will destroy the Cosmos!
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20100911/33575503/attachment-0001.html>


More information about the chuck-users mailing list